我目前有一个包含 3 个 TextView 的布局。
我的问题是如何在这些 TextView 旁边创建一个按钮。
目前我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:textColor="@color/colorAccent" />
<TextView
android:id="@+id/release_at"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#5d5d5d"
android:textStyle="bold" />
</LinearLayout>
这会创建 3 个 TextView ,我的想法是在 TextView 的右侧放置一个按钮,但我不知道如何正确执行此操作。
最佳答案
像这样:
<LinearLayout
heigth=match_parent
width=match_parent
orientation=horizontal
<LinearLayout
heigth=match_parent
width=0dp
layout_weigth=1
orientation=vertical
//Your textviews
</LinearLayout>
<LinearLayout
heigth=match_parent
width=0dp
layout_weigth=1
orientation=vertical
gravity="right"
//Your button
</LinearLayout>
</LinearLayout>
将重力置于右侧会将按钮向右对齐。
关于java - 3 个 TextView 旁边的 Android 布局按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40708274/