我尝试了几种方法,但每次都失败了。
我想要实现的是在ImageView上将TextView居中(水平和垂直方向),但是使用android:layout_centerInParent="true"命令会导致垂直和水平居中于整个区域,而不是在ImageView上。请帮我将父元素附加到TextView或其他解决方法。
这是我的xml代码:
<ImageView
android:id="@+id/imageView1"
android:layout_width="170dp"
android:layout_height="46dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:contentDescription="Your Height BG"
android:src="@drawable/textareabg" />
<TextView
android:id="@+id/textView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Your Height"
android:textColor="#d88b6d"
android:textSize="20sp" />
RelativeLayout
作为父布局,并将其背景设置为ImageView
的背景,但如果您不喜欢这种方式,也可以尝试其他方法。 - Spurdow