简体   繁体   English

为什么在横向,线性布局,按钮下降,我只看到一个空白屏幕?

[英]Why in landscape, linear layout, buttons go down and I see only a blank screen?

I have a problem that when i rotate my phone, screen is blank, I can only see a title of the application. 我有一个问题,当我旋转手机时,屏幕是空白的,我只能看到应用程序的标题。 In landscape mode some buttons go below the screen, and I don't know how to resolve this problem. 在横向模式下,某些按钮位于屏幕下方,我不知道如何解决此问题。 I'm using one linear layout with two linear layouts inside. 我正在使用一个线性布局,里面有两个线性布局。

I have tried to move the buttons, but I can't move them. 我试图移动按钮,但我无法移动它们。

<LinearLayout 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:orientation="vertical"
    tools:context=".QuizActivity">


    <TextView
        android:id="@+id/tvQuestion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="300dp"
        android:layout_marginRight="20dp"
        android:gravity="center"
        android:padding="24dp"
        android:text="@string/textview"
        android:textSize="18sp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:gravity="top"
        android:measureWithLargestChild="true"
        android:orientation="horizontal">


        <Button
            android:id="@+id/btnTrue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/true_button" />

        <Button
            android:id="@+id/btnFalse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/false_button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/imgBtnBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="3dp"
            android:adjustViewBounds="true"
            android:maxWidth="168dp"
            android:maxHeight="42dp"
            android:scaleType="fitCenter"
            android:src="@drawable/left_arrow" />

        <ImageButton
            android:id="@+id/imgBtnNext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="3dp"
            android:adjustViewBounds="true"
            android:maxWidth="168dp"
            android:maxHeight="42dp"
            android:scaleType="fitCenter"
            android:src="@drawable/right_arrow" />
    </LinearLayout>

</LinearLayout>

Just removed android:layout_marginTop="300dp" from textview and added android:gravity="center" in parent LinearLayout. 刚刚从textview中删除了android:layout_marginTop="300dp" ,并在父LinearLayout中添加了android:gravity="center" See the following layout, it will work for landscape also. 请参阅以下布局,它也适用于横向。

<LinearLayout 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:orientation="vertical"
              android:gravity="center"
              >


    <TextView
            android:id="@+id/tvQuestion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:gravity="center"
            android:padding="24dp"
            android:text="textview"
            android:textSize="18sp" />

    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:gravity="top"
            android:measureWithLargestChild="true"
            android:orientation="horizontal">


        <Button
                android:id="@+id/btnTrue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="true_button" />

        <Button
                android:id="@+id/btnFalse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="false_button" />
    </LinearLayout>

    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:orientation="horizontal">

        <ImageButton
                android:id="@+id/imgBtnBack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="3dp"
                android:adjustViewBounds="true"
                android:maxWidth="168dp"
                android:maxHeight="42dp"
                android:scaleType="fitCenter"
                android:src="left_arrow" />

        <ImageButton
                android:id="@+id/imgBtnNext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="3dp"
                android:adjustViewBounds="true"
                android:maxWidth="168dp"
                android:maxHeight="42dp"
                android:scaleType="fitCenter"
                android:src="right_arrow" />
    </LinearLayout>

</LinearLayout>

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

相关问题 为什么 Flow Layout 上的按钮会离开屏幕? - Why do buttons go off screen on Flow Layout? 为什么我的布局在横向模式下没有填满屏幕? - Why is my layout not filling the screen in landscape mode? 限制线性布局内按钮的大小,以防止推离屏幕 - Constrain the size of buttons within a linear layout to prevent pushing off screen 线性布局不会在滚动视图中将父级向下填充到屏幕的剩余部分 - linear layout not filling parent down the remaining part of the screen in a scrollview 当我仅在布局中声明一个按钮时,为什么在我的android应用程序中显示两个按钮 - Why are two buttons showing up in my android application when I only declared one in the layout 为什么用此代码显示黑屏? - Why do I get a blank screen with this code? 如何在android中创建线性布局和中心按钮? - How to create linear layout and center buttons in it in android? 线性布局按钮之间的垂直空间“权重” - Vertically Space "Weight" between Linear Layout Buttons 为什么在按钮中仅看到图像的一部分? - Why I see only part of the image in the button? 我扩展了有关抽屉类的myClass,我看到了myClass布局,但是我无法单击按钮 - I extended myClass about drawer class, I see layout myClass but I cannot click in buttons
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM