将视图置于另一个视图中心(Center a view in relation to another)
下面的代码不是垂直居中的视图对象相对于TextView但它被卡在顶部。
我怎样才能让它垂直居中?
谢谢。
<?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="wrap_content"> <TextView android:id="@+id/label_TV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" android:text="@string/station" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:layout_gravity="center_vertical" android:layout_toRightOf="@id/label_TV" android:layout_toEndOf="@id/label_TV" android:background="@color/divider" /> </RelativeLayout>The code below is not centering the view object vertically in relation to the TextView but it is stuck in the top.
How can I get it centered vertically?
Thank you.
<?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="wrap_content"> <TextView android:id="@+id/label_TV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" android:text="@string/station" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:layout_gravity="center_vertical" android:layout_toRightOf="@id/label_TV" android:layout_toEndOf="@id/label_TV" android:background="@color/divider" /> </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"> <TextView android:id="@+id/label_TV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centverVertical="true" android:layout_gravity="start" android:text="@string/station" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:layout_centverVertical="true" android:layout_toRightOf="@id/label_TV" android:layout_toEndOf="@id/label_TV" android:background="@color/divider" /> </RelativeLayout>Try this,
<?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"> <TextView android:id="@+id/label_TV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centverVertical="true" android:layout_gravity="start" android:text="@string/station" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:layout_centverVertical="true" android:layout_toRightOf="@id/label_TV" android:layout_toEndOf="@id/label_TV" android:background="@color/divider" /> </RelativeLayout>更多推荐
发布评论