【发布时间】:2015-09-22 17:55:57
【问题描述】:
我有一个卡片视图,它必须显示一个图标、一个标题和副标题,如下图所示。
-------------------------------------------- | -------- | | | | TextView_1 | | | Icon | TextView_2 | | | | | | ________ | ____________________________________________
我想要的是让 TextView_1 和 TextView_2 垂直居中,但我无法得到它。我知道我可以使用 LinearLayout 水平和 LinearLayout 垂直。我想要的是得到相同的结果,但只使用 相对布局。在我正在使用的代码下方:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="@dimen/normal_spacing"
android:src="@drawable/icon" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/icon"
android:layout_toRightOf="@+id/icon"
tools:text="Title" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toEndOf="@+id/icon"
android:layout_toRightOf="@+id/icon"
android:textStyle="bold"
tools:text="Subtitle" />
</RelativeLayout>
关于如何将两个文本视图垂直居中的任何想法? :-)
【问题讨论】:
-
你需要两个相对的布局。外层和内层有两个文本字段,如下所示:Rel -image -Rel --tv --tv2 -/Rel /Rel
-
你应该将一个视图对齐到图像顶部,另一个视图到底部
标签: android android-layout android-relativelayout