Android 将两个布局放置在一起

Android 将两个布局放置在一起,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我的布局如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" and

我的布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/ightwall"
    android:id="@+id/drawerlayout"
    >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#6CEB87"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="my list"/>
        </LinearLayout>

    </ScrollView>

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

        <ImageView
            android:id="@+id/mylist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_mylist"
            android:adjustViewBounds="true"
            android:maxHeight="100dp"
            android:maxWidth="100dp"/>

        <ImageView
        android:id="@+id/freeadd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/createlist_freetext"
        android:adjustViewBounds="true"
        android:maxHeight="100dp"
        android:maxWidth="100dp"/>

        <ImageView
            android:id="@+id/categoryadd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_categorysearch"
            android:adjustViewBounds="true"
            android:maxHeight="100dp"
            android:maxWidth="100dp"/>

        <ImageView
            android:id="@+id/favproductadd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_favproduct"
            android:adjustViewBounds="true"
            android:maxHeight="100dp"
            android:maxWidth="100dp"/>



    </LinearLayout>
</LinearLayout>

我希望两个线性层看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/ightwall"
    android:id="@+id/drawerlayout"
    >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#6CEB87"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="my list"/>
        </LinearLayout>

    </ScrollView>

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

        <ImageView
            android:id="@+id/mylist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_mylist"
            android:adjustViewBounds="true"
            android:maxHeight="100dp"
            android:maxWidth="100dp"/>

        <ImageView
        android:id="@+id/freeadd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/createlist_freetext"
        android:adjustViewBounds="true"
        android:maxHeight="100dp"
        android:maxWidth="100dp"/>

        <ImageView
            android:id="@+id/categoryadd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_categorysearch"
            android:adjustViewBounds="true"
            android:maxHeight="100dp"
            android:maxWidth="100dp"/>

        <ImageView
            android:id="@+id/favproductadd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_favproduct"
            android:adjustViewBounds="true"
            android:maxHeight="100dp"
            android:maxWidth="100dp"/>



    </LinearLayout>
</LinearLayout>

我在安卓工作室开发。 我需要红色布局填充固定宽度,绿色布局填充屏幕的其余部分


android:layout\u weight=“1”
添加到第二个
LinearLayout
,并将宽度设置为0

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/ightwall"
    android:id="@+id/drawerlayout"
    >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

        ...

    </ScrollView>

    <LinearLayout
        android:layout_width="0dp" // change
        android:layout_weight="1" // add layout_weight
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#D5D4D4">

        ...

    </LinearLayout>
</LinearLayout>

...
...

在主布局中设置
android:weightSum=“1”
并将
android:layout\u weight
layout\u width在设置布局权重时应为0dp
)赋予其他两个布局

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerlayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:weightSum="1" >

        <ScrollView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:layout_weight=".7" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="#6CEB87"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="my list" />
            </LinearLayout>
        </ScrollView>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
android:weightSum="4"
            android:layout_gravity="right"
            android:layout_weight=".3"
            android:background="#D5D4D4"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/mylist"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
            android:layout_weight="1"
                android:adjustViewBounds="true"
                android:maxHeight="100dp"
                android:maxWidth="100dp"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/freeadd"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
            android:layout_weight="1"
                android:adjustViewBounds="true"
                android:maxHeight="100dp"
                android:maxWidth="100dp"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/categoryadd"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
            android:layout_weight="1"
                android:adjustViewBounds="true"
                android:maxHeight="100dp"
                android:maxWidth="100dp"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/favproductadd"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
            android:layout_weight="1"
                android:adjustViewBounds="true"
                android:maxHeight="100dp"
                android:maxWidth="100dp"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>

    </LinearLayout>


它可以工作,谢谢,但是如果我需要红色布局来包装它的内容?我需要改变什么?我需要和里面的按钮一样大,是什么意思?通过图像解释使用match_parent而不是wrap_按钮中的内容我可以使布局与内容匹配吗?看到我的图像。。你想控制红色版面的全宽吗?