Bố cục của tôi có ImageView (iv) và TextView (tv). Tôi muốn để quyền tv của iv. Và chiều cao của TV giống như chiều cao của iv. TV Gravity được đặt là CENTER_VERTICAL.Cách để ImageView và TextView có cùng chiều cao
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/iv"
android:text="TextView" android:gravity="center_vertical"/>
</RelativeLayout>
Làm cách nào để đạt được mục tiêu?
bạn có thể sử dụng LinearLayout thay vì RelativeLayout, sau đó bạn có thể sử dụng tham số layout_weight như 1 cho cả ImageView và TextView –
Làm thế nào bạn sẽ có cùng chiều cao cho cả hai widget? chiều cao textview phụ thuộc vào kích thước văn bản. Chúng ta chỉ có thể đứng cạnh nhau, chúng ta không thể đảm bảo chiều cao như nhau. –