简体   繁体   English

横向旋转时按钮被切断(Android XML)

[英]Buttons getting cut off in landscape rotation (Android XML)

When I rotate my screen to landscape mode, a DialogFragment containing this layout is cutting off the two buttons at the bottom: 当我将屏幕旋转到横向模式时,包含此布局的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>

Am I doing something wrong or missing something obvious? 我是在做错什么还是错过了明显的事情? How can I get it to force display everything? 我如何才能强制显示所有内容?

I think the case is your screen is simply not large enough to show the whole content. 我认为情况是您的屏幕根本不够大,无法显示全部内容。 Android does not add the scroll functionality if content is larger then the screen. 如果内容大于屏幕,则Android不会添加滚动功能。 If this is the case wrap all your views in a ScrollView so that the buttons could be visible after scrolling. 在这种情况下,将所有视图包装在ScrollView以便在滚动后可以看到按钮。 Like this: 像这样:

<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>

Also you may put ScrollView as Your Parent View 您也可以将ScrollView用作父视图

<ScrollView 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">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!-- Putt all your view here -->

        </LinearLayout>
    </ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM