gpt4 book ai didi

Android textview 使用作为标签和值

转载 作者:IT王子 更新时间:2023-10-28 23:30:14 30 4
gpt4 key购买 nike

我想将两个 TextView 分组到一个组中,并像标签和值一样使用。是否有任何组件可以在 android 中对两个 TextView 进行分组?在android布局中如何实现?

Sample label value

最佳答案

您可以使用 <LinearLayout>水平分组元素。您还应该使用样式来设置边距、背景和其他属性。这将允许您不为您使用的每个标签重复代码。这是一个例子:

<LinearLayout
style="@style/FormItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="@style/FormLabel"
android:layout_width="wrap_content"
android:layout_height="@dimen/default_element_height"
android:text="@string/name_label"
/>

<EditText
style="@style/FormText.Editable"
android:id="@+id/cardholderName"
android:layout_width="wrap_content"
android:layout_height="@dimen/default_element_height"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:hint="@string/card_name_hint"
android:imeOptions="actionNext"
android:singleLine="true"
/>
</LinearLayout>

您还可以根据上面的布局创建自定义 View 。你看过Creating custom view ?

关于Android textview 使用作为标签和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13583549/

30 4 0