我有以下的布局中AlertDialog自定义视图。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_gravity="center"
android:gravity="center"
android:padding="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:columnCount="3">
<TextView
android:id="@+id/code1"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:gravity="center"
android:text="\u2022"
android:textSize="@dimen/match_code_digit_size"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/code2"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="\u2022"
android:textSize="@dimen/match_code_digit_size"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/code3"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:gravity="center"
android:text="\u2022"
android:textSize="@dimen/match_code_digit_size"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k1"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="1"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k2"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="2"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k3"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="3"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k4"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="4"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k5"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="5"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k6"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="6"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k7"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="7"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k8"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="8"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k9"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="9"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k0"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:layout_column="1"
android:text="0"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
</GridLayout>
<TextView
android:id="@+id/error"
style="@style/ErrorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/match_error"
android:visibility="invisible" />
</LinearLayout>
<FrameLayout
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80ffffff"
android:visibility="visible">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
对不起,大量布局,把它放在这里“是”。
注重与ID进步底部的FrameLayout。尽管它的android:layout_height =“match_parent”,在设备上,它看起来像“WRAP_CONTENT” - 有身高只有匹配内部进度。虽然在完美的Android所示Studio设计,占据了看法。
怎么了?
下面是布局如何看起来AS设计师
和在设备上(尝试都仿真器和实际装置中,同样的效果)
尝试改变根本的FrameLayout到的RelativeLayout
你有两个FrameLayouts。 @id一个进步和LinearLayout
一个。
首先快速浏览一下developer.android.com
的FrameLayout被设计为阻挡的区域中的屏幕上显示单个项目。一般情况下,应FrameLayout里被用来保存单个子视图,因为它可以是难以组织的方式,就是扩展到不同的屏幕尺寸没有把孩子相互重叠的子视图。
因此,对于你父母FrameLayout
你有几个孩子?(2)
你可以,但是,多个孩子添加到FrameLayout里,通过使用Android的重力分配到每一个孩子,控制的FrameLayout中的位置:layout_gravity属性。
有没有在你的两个孩子的任何重力?不,不是的@id进展
孩子的意见被描绘在一个堆栈,顶部最近添加的孩子。该FrameLayout里的大小是其最大的孩子(加垫)的大小,可见或不可见(如果FrameLayout里的父许可证)。
所以,首先你加线性布局,然后你添加的FrameLayout所以..孩子FrameLayout
应该在最前面,它是。这是你的问题吧?
即使你的布局是在长可以缩短这个
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center"
android:background="#121"
android:orientation="vertical">
</LinearLayout>
<FrameLayout
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#567"
android:visibility="visible">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
输出(I增加了线性布局你缺少你的孩子框架布局重心的图像):
我有同样的问题,并设法解决它。好像没有人注意到,但你的问题的根源是GridLayout
。正如你可以在蓝图看到有一个与FrameLayout
,因为它确实是匹配父没问题。您GridLayout
的项目有一个固定的大小,这是错误的。您需要设置的权重为每个项目在GridLayout
,这样的项目可以拉伸,以适应任何屏幕分辨率。但在GridLayout
权重需要API 21.因此,我建议你使用与设置为1项的权重的嵌套LinearLayout's
。
我对我的项目的问题是,我有两个框架布局中使用相同的ID。解决的办法是分配唯一的ID到帧布局。
希望这有助于未来的读者。