5

Tôi có một bố cục đơn giản:TextView "fill_parent" không điền vào phụ huynh

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</LinearLayout> 

Nhưng TextView của tôi không được tham gia tất cả các độ rộng mặc dù tôi đã làm fill_parent. Làm thế nào tôi có thể làm cho nó với kích thước đầy đủ thay vì chỉ kích thước của nội dung?

Trả lời

7

Làm cho bên ngoài LinearLayout để có match_parent thay vì wrap_content trong các thuộc tính android:layout_widthandroid:layout_height.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
+0

Oh hoàn hảo! Ngoài ra sự khác nhau giữa fill_parent và match_parent là gì? –

+2

Cả hai đều giống nhau nhưng 'fill_parent' đã bị khấu hao kể từ API 8. –

Các vấn đề liên quan