Android 如何相对调整中心位置
这是我的xml代码 我想在TextView2中使用layout_alignCenter=“@+id/textView1” 但是没有一个中心Android 如何相对调整中心位置,android,textview,android-relativelayout,Android,Textview,Android Relativelayout,这是我的xml代码 我想在TextView2中使用layout_alignCenter=“@+id/textView1” 但是没有一个中心 我认为布局\u centerVertical或centerInp也没有用。您可以将RelativeLayout包装在线性布局中,并使用空格元素: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/a
我认为布局\u centerVertical或centerInp也没有用。您可以将
RelativeLayout
包装在线性布局中,并使用空格
元素:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="78dp"
android:layout_marginTop="199dp"
android:text="test" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:text="I want to align Center" />
</RelativeLayout>
空格
元素将根据布局权重,在所有空格
元素之间相对地分配空白。您希望显示屏幕正中央的文本视图……然后使用下面修改的代码
<LinearLayout layout_width="0dp" layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="78dp"
android:layout_marginTop="199dp"
android:text="test" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:text="I want to align Center" />
</RelativeLayout>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
这肯定对你有用。如果有任何其他要求,请详细解释
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:text="test" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:text="I want to align Center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"/>
</RelativeLayout>