- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在测试我在博客文章中找到的“ScalingLinearLayout”。 http://www.quadra-tec.net/~floppie/blag/2013/01/scalinglinearlayout-auto-scaling-layouts-in-android/ .
我的问题是图形布局编辑器的主预览窗口是黑色的,而其他窗口显示预览(见下图)。
我之前在自定义组件中看到过类似的行为,但根据我的经验,总是什么都不显示。
有没有人以前见过这种行为并且知道是什么原因造成的?
请同时查看下面的相关代码
图像中的示例布局:
<com.nightfox.testapp.ScalingLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical"
tools:context=".FlowA1" >
<RelativeLayout
android:layout_width="640px"
android:layout_height="960px"
android:gravity="center|bottom" >
<Button
android:id="@+id/button1"
android:layout_width="400px"
android:layout_height="200px"
android:layout_alignParentTop="true"
android:text="@string/no_set_alarm" />
<Button
android:id="@+id/button1"
android:layout_width="400px"
android:layout_height="200px"
android:layout_alignParentBottom="true"
android:text="@string/no_set_alarm" />
</RelativeLayout>
自定义 ScalingLinearLayout 如下所示:
package com.nightfox.testapp;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.LinearLayout;
public class ScalingLinearLayout extends LinearLayout {
int baseWidth;
int baseHeight;
boolean alreadyScaled;
float scale;
int expectedWidth;
int expectedHeight;
public ScalingLinearLayout(Context context) {
super(context);
Log.d("notcloud.view", "ScalingLinearLayout: width=" + this.getWidth() + ", height=" + this.getHeight());
this.alreadyScaled = false;
}
public ScalingLinearLayout(Context context, AttributeSet attributes) {
super(context, attributes);
Log.d("notcloud.view", "ScalingLinearLayout: width=" + this.getWidth() + ", height=" + this.getHeight());
this.alreadyScaled = false;
}
public void onFinishInflate() {
Log.d("notcloud.view", "ScalingLinearLayout::onFinishInflate: 1 width=" + this.getWidth() + ", height=" + this.getHeight());
// Do an initial measurement of this layout with no major restrictions on size.
// This will allow us to figure out what the original desired width and height are.
this.measure(1000, 1000); // Adjust this up if necessary.
this.baseWidth = this.getMeasuredWidth();
this.baseHeight = this.getMeasuredHeight();
Log.d("notcloud.view", "ScalingLinearLayout::onFinishInflate: 2 width=" + this.getWidth() + ", height=" + this.getHeight());
Log.d("notcloud.view", "ScalingLinearLayout::onFinishInflate: alreadyScaled=" + this.alreadyScaled);
Log.d("notcloud.view", "ScalingLinearLayout::onFinishInflate: scale=" + this.scale);
if(this.alreadyScaled) {
Scale.scaleViewAndChildren((LinearLayout)this, this.scale, 0);
}
}
public void draw(Canvas canvas) {
// Get the current width and height.
int width = this.getWidth();
int height = this.getHeight();
// Figure out if we need to scale the layout.
// We may need to scale if:
// 1. We haven't scaled it before.
// 2. The width has changed.
// 3. The height has changed.
if(!this.alreadyScaled || width != this.expectedWidth || height != this.expectedHeight) {
// Figure out the x-scaling.
float xScale = (float)width / this.baseWidth;
if(this.alreadyScaled && width != this.expectedWidth) {
xScale = (float)width / this.expectedWidth;
}
// Figure out the y-scaling.
float yScale = (float)height / this.baseHeight;
if(this.alreadyScaled && height != this.expectedHeight) {
yScale = (float)height / this.expectedHeight;
}
// Scale the layout.
this.scale = Math.min(xScale, yScale);
Log.d("notcloud.view", "ScalingLinearLayout::onLayout: Scaling!");
Scale.scaleViewAndChildren((LinearLayout)this, this.scale, 0);
// Mark that we've already scaled this layout, and what
// the width and height were when we did so.
this.alreadyScaled = true;
this.expectedWidth = width;
this.expectedHeight = height;
// Finally, return.
return;
}
super.draw(canvas);
}
和比例类:
package com.nightfox.testapp;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
public class Scale {
public static void scaleContents(View rootView, View container) {
Scale.scaleContents(rootView, container, rootView.getWidth(), rootView.getHeight());
}
// Scales the contents of the given view so that it completely fills the given
// container on one axis (that is, we're scaling isotropically).
public static void scaleContents(View rootView, View container, int width, int height) {
Log.d("notcloud.scale", "Scale::scaleContents: container: " + container.getWidth() + "x" + container.getHeight() + ".");
// Compute the scaling ratio
float xScale = (float)container.getWidth() / width;
float yScale = (float)container.getHeight() / height;
float scale = Math.min(xScale, yScale);
// Scale our contents
Log.d("notcloud.scale", "Scale::scaleContents: scale=" + scale + ", width=" + width + ", height=" + height + ".");
scaleViewAndChildren(rootView, scale, 0);
}
// Scale the given view, its contents, and all of its children by the given factor.
public static void scaleViewAndChildren(View root, float scale, int canary) {
// Retrieve the view's layout information
ViewGroup.LayoutParams layoutParams = root.getLayoutParams();
// Scale the View itself
if(layoutParams.width != ViewGroup.LayoutParams.MATCH_PARENT && layoutParams.width != ViewGroup.LayoutParams.WRAP_CONTENT) {
layoutParams.width *= scale;
}
if(layoutParams.height != ViewGroup.LayoutParams.MATCH_PARENT && layoutParams.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
layoutParams.height *= scale;
}
// If the View has margins, scale those too
if(layoutParams instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams)layoutParams;
marginParams.leftMargin *= scale;
marginParams.topMargin *= scale;
marginParams.rightMargin *= scale;
marginParams.bottomMargin *= scale;
}
root.setLayoutParams(layoutParams);
// Same treatment for padding
root.setPadding(
(int)(root.getPaddingLeft() * scale),
(int)(root.getPaddingTop() * scale),
(int)(root.getPaddingRight() * scale),
(int)(root.getPaddingBottom() * scale)
);
// If it's a TextView, scale the font size
/*
if(root instanceof TextView) {
TextView tv = (TextView)root;
tv.setTextSize(tv.getTextSize() * scale); //< We do NOT want to do this.
}
*/
// If it's a ViewGroup, recurse!
if(root instanceof ViewGroup) {
ViewGroup vg = (ViewGroup)root;
for(int i = 0; i < vg.getChildCount(); i++) {
scaleViewAndChildren(vg.getChildAt(i), scale, canary + 1);
}
}
}
最佳答案
这是因为您已经编辑了该特定 xml 文件的主题。你只需要点击你想要的 xml 并从你选择的 nexus S 屏幕右侧的主题选项中更改它的主题......或者你可以转到 res>values>strings 并更改负责的字符串用于主题选择。
关于具有自定义布局的 Android 图形布局编辑器黑色主窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18037674/
我听说过两种数据库架构。 大师级 主从 master-master不是更适合现在的web吗,因为它就像Git一样,每个单元都有整套数据,如果一个宕机也无所谓。 主从让我想起了 SVN(我不喜欢它),你
我们当前将 MySQL 配置为支持故障转移:Site1 Site2。当它们被设置为主/主时。在给定时间点,应用程序服务器仅主动写入一个站点。我们想要设置一个新的故障转移站点。然后我们将拥有 Site
我听说过两种数据库架构。 大师-大师 主从 master-master 不是更适合当今的网络吗,因为它就像 Git,每个单元都有整套数据,如果其中一个发生故障,也没关系。 主从让我想起 SVN(我不喜
我正在创建一个标记为类别的表,其中主类别(父列)包含 0,子类别包含父类别的 ID。我听说这叫引用。我的问题:这张表的结构正确吗?或者是否有更好的方法,例如实现遍历树或类似方法? CREATE TAB
我正在阅读一份关于 C++ 与 C 的文档。该文档说与 C 相比,C++ 编写得非常紧凑。一个例子是,C 允许 main() 函数类型为 void。另一方面,C++ 不允许这样做,他给出了标准中的以下
C main函数和Java main函数有什么区别? int main( int argc, const char* argv[] ) 对比 public static void main(Strin
我一直摸不着头脑,但运气不好。设计器有一个包含 3 栏的站点、两个侧边栏和一个主要内容区域。 专为桌面设计,左栏、主要内容、右栏。但是,在较小的设备上,我们希望首先堆叠主要内容。 所以通常情况下,你可
我一直在阅读有关 Jenkins 主/从配置的信息,但我仍然有一些问题: 是不是真的没有像 Jenkins 主站那样安装和启动从站 Jenkins?我假设我会以相同的方式安装一个主 Jenkins 和
据我了解,Viemodel中MVVM背后的概念包括业务逻辑和/或诸如暴露于 View 的数据的主/明细关系之类的事物 因此,正如我发现的那样,有很多ORM生成器,例如模型的telerik a.o以及另
我们有一个群集,其中包含3个主分区,每个主分区有2个副本。主/副本分片的总文档数相同;但是,对于同一查询/文档,我们得到3个不同的分数。当我们将preference = primary添加为查询参数时
我有一个非常大/旧/长时间运行的项目,它使用相对于启动目录的路径访问文件资源(即应用程序仅在从特定目录启动时才工作)。当我需要调试程序时,我可以从 eclipse 启动它并使用“运行配置”->->“工
谁能向我解释一下为什么我在这段代码上遇到段错误?我一直试图弄清楚这一点,但在各种搜索中却一无所获。当我运行代码而不调用 main(argc, argv) 时,它会运行。 Slave 仅将 argv 中
使用 xcode 中的默认项目作为主从应用程序,如果我在折叠委托(delegate)中放置 print 调试语句,当我旋转设备时它似乎永远不会被触发(事实上我永远无法触发它)。 我编辑的代码位于 Ap
是否有任何产品可以使 mysql 主/从故障转移过程更容易?一些可以自动发生的事情,而不是手动修复它。 最佳答案 [...稍后...;) 你所说的“更容易”是什么?MySQL 有很多解决方案: MyS
我有两个 mysql 数据库。我想做主/主复制。 复制以一种方式进行。然而,反过来说却不然。该错误表明它无法与用户“test@IPADDRESS”连接。 如何将用户名更改为 repl?从未进行过测试,
我正在尝试在 MySQL 中运行以下查询: GRANT REPLICATION SLAVE ON *.* TO 'replication'@’10.141.2.%’ IDENTIFIED BY ‘sl
我正在尝试使用 Android 提供的主/详细流程模板创建一个应用程序,并且我正在尝试将多个操作栏菜单项添加到操作栏的主要部分和详细信息部分。这就是我要实现的目标: (来源:softwarecrew.
我正在寻找一个跨平台的 C++ master/worker 库或工作队列库。一般的想法是我的应用程序将创建某种任务或工作对象,将它们传递给工作主机或工作队列,这将依次在单独的线程或进程中执行工作。为了
我似乎看到很多人在他们的 MySQL 模式中任意分配大尺寸的主/外键字段,例如 INT(11) 甚至 WordPress 使用的 BIGINT(20)。 如果我错了,请纠正我,但即使是 INT(4)
如果我有一个可以与多个键相关联的用户,正确的表设置应该是: 一个表有两列,例如: UserName | Key 没有主键且用户可以有多行,或者: 具有匹配标识符的两个表 Table 1 Us
我是一名优秀的程序员,十分优秀!