【发布时间】:2022-01-03 16:06:15
【问题描述】:
如何分配对象,使 TextView 完全位于父对象的中间,而 ImageButton 位于左侧。尝试为父元素安装
android:gravity="center"
,以及 TextView 本身
android:layout_gravity="center"
,但什么都没有出来。我附上下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".add">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="67dp"
android:orientation="horizontal"
android:gravity="center">
<ImageButton
android:id="@+id/backArrow"
android:layout_width="30dp"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:background="@color/transparent"
android:src="@drawable/back_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/tenor_sans"
android:text="@string/adder"
android:textColor="#2C1E4D"
android:textSize="24sp" />
</LinearLayout>
</RelativeLayout>
【问题讨论】:
标签: java android xml android-layout