Android studio 两个垂直线性布局,希望其中一个比另一个宽

Android studio 两个垂直线性布局,希望其中一个比另一个宽,android-studio,Android Studio,我有一个布局,它是一个相对的布局,包含两个垂直线性布局。每个线性布局使用相同的宽度。方向是横向的,我想让第一个线性布局使用布局的2/3,第二个线性布局使用其他1/3。 我对XML不是很精通。我的背景是VisualBasic,现在使用Android Studio转到Java 下面是用于活动布局的XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schem

我有一个布局,它是一个相对的布局,包含两个垂直线性布局。每个线性布局使用相同的宽度。方向是横向的,我想让第一个线性布局使用布局的2/3,第二个线性布局使用其他1/3。 我对XML不是很精通。我的背景是VisualBasic,现在使用Android Studio转到Java

下面是用于活动布局的XML

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:background="@color/colorBackgroundGray"
        tools:layout="@layout/fragment_select_item"
        tools:context="com.myCompany.myProduct.activities.ReturnAreaActivity">

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

        >
        <FrameLayout
            android:id="@+id/FragmentFrame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


        </FrameLayout>
        <include
            android:id="@+id/include2"
            layout="@layout/frm1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="left"
            android:layout_weight="1.7" />



    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:paddingLeft="5dp"
        android:orientation="vertical">

        <include
            android:id="@+id/include"
            layout="@layout/layout_numpad5"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginStart="220dp"
            android:layout_weight="1.3"
            android:layout_gravity="right"
            />

    </LinearLayout>



</RelativeLayout>

重量是我刚试过的。有什么想法吗?

试试下面的基本逻辑,它在您的情况下会很好地工作

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="2">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="First Linear Layout"
        android:gravity="center"/>
    
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Second Linear Layout"
        android:gravity="center"/>
    
</LinearLayout>

</LinearLayout>

输出:

要更改方向(如果您不想并排布局),只需将value或android:orientation=“vertical”更改为android:orientation=“horizontal”

输出:


您想要两个内部线性布局并排还是一个在另一个下面?