Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android线性布局元素在中间的风景和肖像模式_Java_Android_Xml_Android Layout - Fatal编程技术网

Java Android线性布局元素在中间的风景和肖像模式

Java Android线性布局元素在中间的风景和肖像模式,java,android,xml,android-layout,Java,Android,Xml,Android Layout,我的布局包含三个按钮,一个编辑文本字段和一个按钮。我想把三个按钮放在一行,但在屏幕的中心水平位置。EditText字段应位于按钮下方,EditText字段下方应有一个按钮 以下是我的布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="ma

我的布局包含三个按钮,一个编辑文本字段和一个按钮。我想把三个按钮放在一行,但在屏幕的中心水平位置。EditText字段应位于按钮下方,EditText字段下方应有一个按钮

以下是我的布局:

<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:background="@color/blueAct"
    android:orientation="vertical"
    android:paddingBottom="100.0dip"
    android:paddingLeft="10.0dip"
    android:paddingRight="10.0dip"
    android:paddingTop="100.0dip" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="4.0dip"
        android:paddingLeft="100.0dip"
        android:paddingRight="100.0dip"
        android:paddingTop="5.0dip" >

        <ImageButton
            android:id="@+id/buttonGreen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginRight="4.0dip"
            android:background="@drawable/green_button"
            android:contentDescription="@string/green" />

        <ImageButton
            android:id="@+id/buttonRed"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginRight="4.0dip"
            android:background="@drawable/red_button"
            android:contentDescription="@string/red" />

        <ImageButton
            android:id="@+id/buttonBlue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginRight="4.0dip"
            android:background="@drawable/blue_button"
            android:contentDescription="@string/blue" />
    </LinearLayout>

    <EditText
        android:id="@+id/phone_code"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/phone_code"
        android:paddingTop="100.0dip"
        android:textColor="@color/white"
        android:textColorHint="@color/white" >

        <requestFocus />
    </EditText>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:background="@color/orangeAct"
        android:onClick="searchUsers"
        android:paddingTop="100.0dip"
        android:text="@string/button_go"
        android:textColor="@color/white" />

</LinearLayout>
现在的问题是,如果用户从纵向模式切换到横向模式,三个按钮不在中间。 在不为横向模式创建单独的布局文件的情况下,如何使此“响应”成为可能


任何帮助都将不胜感激。

不要在水平直线布局上使用填充来居中显示视图。相反,您可以在展开之前和之后添加视图,以填充剩余空间

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

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/buttonGreen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />

    <ImageButton
        android:id="@+id/buttonRed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />

    <ImageButton
        android:id="@+id/buttonBlue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ... />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>
为3个相对布局添加了线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@mipmap/background"
    android:orientation="vertical"
    android:id="@+id/homemain124"
    android:weightSum="3">

    <RelativeLayout
        android:id="@+id/paneltamrin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="something"
            android:textColor="#fff"
            android:id="@+id/top1"
            android:gravity="center_horizontal"
            android:layout_marginTop="10dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="40dp"
            android:layout_marginLeft="40dp"
            android:padding="8dp"
            android:background="@drawable/textcorner"
            android:layout_below="@+id/top1"
            android:text="something"
            android:textSize="20sp"
            android:textColor="#fff"
            android:id="@+id/top2"
            android:fontFamily="monospace"
            android:textStyle="bold"
            android:gravity="center_horizontal"
            android:layout_marginTop="30dp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/top2"
            android:text="APPLIED BY"
            android:textSize="15sp"
            android:id="@+id/top3"
            android:textColor="#fff"

            android:gravity="center_horizontal"
            android:layout_marginTop="30dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/top3"

            android:text="COURT OF JUSTICE IN INDIA"
            android:id="@+id/top4"
            android:textSize="15sp"
            android:textColor="#fff"
            android:textStyle="bold"

            android:gravity="center_horizontal"
            android:layout_marginTop="10dp"/>






    </RelativeLayout>



    <RelativeLayout
        android:id="@+id/paneltamrin2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center">

        <ImageView
            android:layout_width="220dp"
            android:layout_height="160dp"
            android:src="@mipmap/book1"
            android:id="@+id/image1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"

            />



        </RelativeLayout>


    <RelativeLayout
        android:id="@+id/paneltamrin3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center">

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="READ NOW"
            android:textColor="#fff"

            android:lineSpacingExtra="10dp"
            android:textSize="20sp"

            android:layout_marginTop="10dp"
            android:layout_marginBottom="15dp"
            android:id="@+id/buttonorder"

            android:padding="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"

            android:background="@drawable/orderbutton"
            android:layout_centerHorizontal="true"/>
        <TextView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#fff"
            android:textSize="13sp"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:layout_below="@+id/buttonorder"

            android:text="something"/>




        </RelativeLayout>




    </LinearLayout>