gpt4 book ai didi

android-layout - 安卓用户界面 : how to align a TextView and two radiobuttons to occupy 1/3rd parent each?

转载 作者:行者123 更新时间:2023-11-29 18:15:39 26 4
gpt4 key购买 nike

我敢肯定它非常简单,我只是太蠢了,但我已经尝试了很多变体,但仍然无法正常工作。更糟糕的是——这 3 个组件在 Eclipse 的图形编辑器中完全按照我想要的方式对齐,但在真实设备上却不是。对于 TextView 和 RadioGroup,我只能将其对齐到 50%。

目前 XML 是这样的(这里我假设 RadioGroup 是一种 LinearLayout):

 <RadioGroup 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:text="@string/CC_Direction_caption" />
<RadioButton
android:id="@+id/rb_toCamera"
style="@style/ButtonStyle"
android:text="@string/CC_Backwards_Caption" />
<RadioButton
android:id="@+id/rb_toInfinity"
style="@style/ButtonStyle"
android:text="@string/CC_Forwards_Caption" />

</RadioGroup>

ButtonStyle 是:

<item name="android:layout_width">0dip</item>
<item name="android:layout_height">70dp</item>
<item name="android:layout_weight">1</item>

所有这些都在 TableRow 中。

最佳答案

在您的 TextView 中使用 android:layout_centerVertical="true"。

下面是一个示例:

             <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >

<TextView
android:id="@+id/typeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="GroupBox Label"
android:textColor="@color/black"
android:textSize="14dp" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_alignParentRight="true"
android:gravity="center"
android:orientation="horizontal" >

<RadioButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio 1 Text"
android:textColor="@color/blue" />

<RadioButton
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio 2 t"
android:textColor="@color/blue" />
</RadioGroup>
</RelativeLayout>

关于android-layout - 安卓用户界面 : how to align a TextView and two radiobuttons to occupy 1/3rd parent each?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8269269/

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