当我将屏幕旋转到横向模式时,包含此布局的 DialogFragment 会切断底部的两个按钮:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alias"/>
<EditText
android:id="@+id/edittext_alias"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:ems="10"
android:layout_marginLeft="4dp"
android:maxLength="30"
android:imeOptions="actionDone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interests"/>
<EditText
android:id="@+id/edittext_interests"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:layout_marginLeft="4dp"
android:maxLength="10"
android:imeOptions="actionDone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bio"/>
<EditText
android:id="@+id/edittext_bio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:ems="10"
android:layout_marginLeft="4dp"
android:maxLines="2"
android:gravity="top"
android:imeOptions="actionDone"
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
android:scrollbars="vertical"
android:fadeScrollbars="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Cancel"
android:layout_weight="1"/>
<Button
android:id="@+id/button_confirm"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="OK"
android:layout_gravity="center_horizontal"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
我是做错了什么还是遗漏了一些明显的东西?我怎样才能让它强制显示所有内容?
最佳答案
我认为情况是您的屏幕不够大,无法显示全部内容。如果内容比屏幕大,Android 不会添加滚动功能。如果是这种情况,请将所有 View 包装在 ScrollView
中,以便按钮在滚动后可见。像这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Putt all your view here -->
</LinearLayout>
</ScrollView>
</LinearLayout>
关于android - 按钮在横向旋转中被切断(Android XML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37620793/