【发布时间】:2015-02-04 07:13:00
【问题描述】:
我有一个包含 ImageView 的相对布局,并希望在活动布局 xml 文件中将 TextView 居中在 ImageView 的一侧。
这是图像视图,然后是我为 TextView 尝试过的内容
这是相对布局的内部:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="170dp"
android:minWidth="170dp"
android:id="@+id/logoBackground"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:layout_marginTop="33dp"
android:contentDescription="@string/content_description_useless"
android:background="#ffffd0cd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/capital_u"
android:id="@+id/textView"
android:textSize="30sp"
android:layout_alignTop="@+id/logoBackground"
android:layout_alignLeft="@+id/logoBackground"
android:layout_alignStart="@+id/logoBackground"
android:layout_marginLeft="43dp"
android:layout_marginStart="43dp"
android:layout_marginTop="65dp"/>
我觉得看起来还可以,但是 marginTop 是 65 不应该是 imageView 高度的一半吗?
提前感谢您的帮助。
【问题讨论】:
-
如果您想为布局添加背景颜色。然后您也可以尝试将其添加到 Theme 中而不是 ImageView 中?
标签: java android xml android-layout