【发布时间】:2017-05-25 21:53:13
【问题描述】:
我在 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>
抱歉,排版量大,按原样放在这里。
注意底部的带有 progress 的 FrameLayout。尽管它有 android:layout_height="match_parent",但在设备上它看起来像“wrap_content” - 高度只匹配内部 ProgressBar。 尽管在 Android Studio 设计器中完美展示,占据了整个视图。
怎么了?
这是 AS 设计器中的布局外观
在设备上(模拟器和真机都试过,效果一样)
【问题讨论】:
-
你能把图片和预期的输出也发一下吗
-
为您的子框架布局添加重力
-
@Alexey 检查我的答案
-
@Alexey 我的回答肯定会有所帮助!
标签: android android-framelayout