android - 按钮在横向旋转中被切断(Android XML)

标签 android xml android-layout android-dialogfragment android-orientation

当我将屏幕旋转到横向模式时,包含此布局的 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/

相关文章:

c++ - XercesDOMParser 和 XIncludes

xml - 将 NCPDP 脚本从 XML 转换为 EDI

java - 如何从 Android 中的 java 代码中删除任何 xml 属性

java - 在矩形内绘制等距矩形

java - 在构造函数上使用具有规范的泛型

java - 如何在 xml 文件开头插入节点?

android - 切换到支持库 26 和 AppBarActivity 到 AppCompatActivity 后工具栏菜单项被挤压

android - 在 android.support.v7.widget.SearchView 的 closeButton 中使用 RTL 方向

android - 奇数ListView

android - 查询部分数据的联系人