Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
Android 水平布局中的嵌套垂直布局_Android_Xml_Android Layout_Android Fragments_Android Studio - Fatal编程技术网

Android 水平布局中的嵌套垂直布局

Android 水平布局中的嵌套垂直布局,android,xml,android-layout,android-fragments,android-studio,Android,Xml,Android Layout,Android Fragments,Android Studio,我正在创建一个android应用程序,我想创建一个布局,有两个按钮并排,下面有三个按钮。我正在尝试做的一个例子可以在这里找到: 我正在努力使两个按钮在水平线性布局中并排,在垂直线性布局中也有三个按钮。由于第一个线性布局是水平的,这将使我的按钮成为水平以及。我的代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.co

我正在创建一个android应用程序,我想创建一个布局,有两个按钮并排,下面有三个按钮。我正在尝试做的一个例子可以在这里找到:

我正在努力使两个按钮在水平线性布局中并排,在垂直线性布局中也有三个按钮。由于第一个线性布局是水平的,这将使我的按钮成为水平以及。我的代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:weightSum="1">

<TextView
        android:layout_width="164dp"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView2"
        android:layout_gravity="left"
        android:layout_weight="0.1" />

    <TextView
        android:layout_width="174dp"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView"
        android:layout_gravity="right"
        android:layout_weight="0.1" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    style="@style/AppTheme"
    android:longClickable="false"
    android:weightSum="1">



    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btnFitnessGoalsDefaultString"
        android:textColor="#FFFFFF"
        android:id="@+id/btnFitnessGoals"
        android:background="@drawable/buttondefault"
        android:layout_marginBottom="10dp"
        android:layout_weight="0.10"
        android:layout_gravity="top" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:text="@string/btnNutritionGoalsDefaultString"
        android:textColor="#FFFFFF"
        android:id="@+id/btnNutritionGoals"
        android:background="@drawable/buttondefault"
        android:layout_weight="0.10" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btnBonusEventsDefaultString"
        android:textColor="#FFFFFF"
        android:id="@+id/btnBonusEvents"
        android:background="@drawable/buttondefault"
        android:layout_weight="0.10" />
</LinearLayout>
</LinearLayout>

你需要这样做

<LinearLayout
    android:orientation="vertical">

      <LinearLayout
         android:orientation="horizontal">

           <!-- horizontal buttons here -->

      </LinearLayout>

      <LinearLayout
        android:orientation="vertical">

           <!-- vertical buttons here -->

      </LinearLayout>
</LinearLayout>

你需要这样做

<LinearLayout
    android:orientation="vertical">

      <LinearLayout
         android:orientation="horizontal">

           <!-- horizontal buttons here -->

      </LinearLayout>

      <LinearLayout
        android:orientation="vertical">

           <!-- vertical buttons here -->

      </LinearLayout>
</LinearLayout>

使用类似以下内容:

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

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>

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

        <Button
                android:id="@+id/button3"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Button" />

            <Button
                android:id="@+id/button4"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Button" />

            <Button
                android:id="@+id/button5"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Button" />

    </LinearLayout>

</LinearLayout>

使用类似以下内容:

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

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>

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

        <Button
                android:id="@+id/button3"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Button" />

            <Button
                android:id="@+id/button4"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Button" />

            <Button
                android:id="@+id/button5"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Button" />

    </LinearLayout>

</LinearLayout>
简单一点:

<LinearLayout
  android:orientation="vertical">

  <LinearLayout
     android:orientation="horizontal">

       <!-- horizontal buttons here -->

  </LinearLayout>

       <!-- vertical buttons here -->

</LinearLayout>
简单一点:

<LinearLayout
  android:orientation="vertical">

  <LinearLayout
     android:orientation="horizontal">

       <!-- horizontal buttons here -->

  </LinearLayout>

       <!-- vertical buttons here -->

</LinearLayout>

此布局可与所有设备屏幕配合使用。试试看

<?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:orientation="vertical" >

<!-- 2 buttons side by side -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <!-- btn 1 -->

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#00ff00"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 1" />
    </FrameLayout>

    <!-- btn 2 -->

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#446600"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 2" />
    </FrameLayout>
</LinearLayout>

<!-- three buttons underneath -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="vertical" >

    <!-- btn 3 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#dd77ff"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 3" />
    </FrameLayout>
    <!-- btn 4 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#9977ff"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 4" />
    </FrameLayout>
    <!-- btn 5 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#1277ff"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 5" />
    </FrameLayout>
</LinearLayout>

此布局可与所有设备屏幕配合使用。试试看

<?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:orientation="vertical" >

<!-- 2 buttons side by side -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <!-- btn 1 -->

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#00ff00"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 1" />
    </FrameLayout>

    <!-- btn 2 -->

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#446600"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 2" />
    </FrameLayout>
</LinearLayout>

<!-- three buttons underneath -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="vertical" >

    <!-- btn 3 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#dd77ff"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 3" />
    </FrameLayout>
    <!-- btn 4 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#9977ff"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 4" />
    </FrameLayout>
    <!-- btn 5 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#1277ff"
        android:foreground="?android:attr/selectableItemBackground" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button 5" />
    </FrameLayout>
</LinearLayout>

谢谢你的帮助!!谢谢你的帮助!!