【发布时间】:2018-03-08 00:01:50
【问题描述】:
我带着一个看似简单的问题来找你。但是我找不到合适的解决方案。 我在 LinearLayout 中的 RelativeLayout 中有一个 Image- 和一个 TextView。
<LinearLayout
android:id="@+id/page2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
android:baselineAligned="false"
android:divider="@drawable/separator_vertical"
android:showDividers="middle">
<RelativeLayout
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/delete_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="DemoText"
android:textColor="#fff"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_toStartOf="@id/delete_text"
android:src="@drawable/ic_delete" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/edit_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="DemoText"
android:textColor="#fff"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_toStartOf="@id/edit_text"
android:src="@drawable/ic_edit" />
</RelativeLayout>
</LinearLayout>
目前只有TextView在各自的RelativeLayout中居中。 如何在 RelativeLayout 的中心对齐 ImageView 和 TextView?
【问题讨论】:
-
尝试使用权重和宽度为 0 dp 的相对布局,使用
android:gravity="center"希望它能解决您的问题.. :) -
谢谢解决了! :)
-
好的,那我可以结束这个问题了。
标签: android android-layout android-relativelayout