【发布时间】:2017-01-14 17:26:02
【问题描述】:
我在相对布局中有一个图像和一个文本视图。图像和文本视图占据了屏幕宽度的 50%。如何使图像和 textview 居中?尝试了很多方法,不知道自己做错了什么……
这是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewEventImage"
android:adjustViewBounds="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/eventNameBackground"
android:id="@+id/textViewEventName"
android:textColor="@android:color/white"
android:textSize="15sp"/>
</RelativeLayout>
</LinearLayout>
【问题讨论】:
-
你想让你的图片成为屏幕的中心吗?