我有一个布局,它是一个包含2个垂直线性布局的relativeLayout。每个线性布局使用相等的宽度。方向是横向,我想使第一个线性布局使用2/3的布局,第二个linearlayout使用另一个1/3。 我不熟悉XML。我的背景是Visual Basic,现在使用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>
答案 0 :(得分:0)
尝试以下基本逻辑,它可以正常使用
<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>
输出:
要改变方向(如果你不要并排布局)只需更改值或android:orientation =“vertical”到android:orientation =“horizontal”。
输出: