gpt4 book ai didi

android - 在相对布局中设置宽度比例

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:10 25 4
gpt4 key购买 nike

我是 Android 布局的新手。

我正在尝试以 1:3:1 的比例设置 Age:EditText:Year,并在 Height 上设置相同的大小。

我应该使用 TableLayout 吗?如果是,当我在其他行中做一些事情时,如何防止 TableRow1 改变宽度等?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<TextView
android:id="@+id/txtAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/search_text"
android:layout_alignBottom="@+id/search_text"
android:layout_alignParentLeft="true"
android:text="Age"
android:layout_weight="0.3"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/txtYears"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/search_text"
android:layout_alignBottom="@+id/search_text"
android:layout_alignParentRight="true"
android:text="Years"
android:layout_weight="0.3"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/search_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/txtYears"
android:layout_toRightOf="@id/txtAge"
android:ems="10"
android:hint="Enter your age"
android:inputType="text|number"
android:lines="1"
android:layout_weight="0.7"
android:maxLength="2"
android:maxLines="1" />



<TextView
android:id="@+id/txtHeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/enterHeight"
android:layout_below="@+id/search_text"
android:text="Height"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"/>

<Spinner
android:id="@+id/spinHeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/txtHeight"
android:layout_weight="1" />

<EditText
android:id="@+id/enterHeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/search_text"
android:layout_toLeftOf="@+id/spinHeight"
android:layout_toRightOf="@+id/txtHeight"
android:ems="10"
android:hint="Enter your height"
android:inputType="text|number"
android:lines="1"
android:layout_weight="3"
android:maxLength="3"
android:maxLines="1" >

<requestFocus />
</EditText>

</RelativeLayout>

最佳答案

我想这就是你想要的。见下图。

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:weightSum="100" >

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:gravity="center_vertical|center_horizontal"
android:text="Age"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />

<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:gravity="center_vertical|center_horizontal"
android:text="Years"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:weightSum="100" >

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:gravity="center_vertical|center_horizontal"
android:text="Height"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />

<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60" />

<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20" />
</LinearLayout>

</LinearLayout>

enter image description here

关于android - 在相对布局中设置宽度比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13528072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com