您好,我无法将 TextView 置于 ImageView 的中心。我希望它看起来有点像这样,但让它实际上垂直居中,并在字体大小发生变化时保持垂直居中。
这是我在 XML 中的内容,我不在乎是否需要将相对布局更改为另一种对我来说无关紧要的布局,我只是希望能够将其居中。 xml 如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.spencer.app.ProfileActivity"
android:id="@+id/layout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="140dp"
android:minWidth="140dp"
android:id="@+id/logoBackground"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
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/u_textView"
android:textSize="80sp"
android:layout_marginLeft="31dp"
android:layout_marginStart="31dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_alignTop="@+id/logoBackground"
android:layout_alignLeft="@+id/logoBackground"
android:layout_alignStart="@+id/logoBackground" />
</RelativeLayout>
感谢您提前提供的帮助。
最佳答案
试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.spencer.app.ProfileActivity" >
<ImageView
android:id="@+id/logoBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
android:background="#ffffd0cd"
android:contentDescription="@string/content_description_useless"
android:minHeight="140dp"
android:minWidth="140dp" />
<TextView
android:id="@+id/u_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/logoBackground"
android:layout_alignLeft="@+id/logoBackground"
android:layout_alignRight="@+id/logoBackground"
android:layout_alignStart="@+id/logoBackground"
android:layout_alignTop="@+id/logoBackground"
android:text="@string/capital_u"
android:textSize="80sp"
android:gravity="center" />
</RelativeLayout>
关于java - Android - 布局内其他 View 中的中心 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27327630/