2015-05-17 18 views
0

У меня проблема с пользовательским RowLayout, используемым для ListView в Android. Он содержит ImageView и TextView. Изображение появится, однако текст не будет. Может ли кто-нибудь сказать мне, что я сделал неправильно?Android Custom Row Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="80dp" 
android:layout_height="80dp" 
android:weightSum="1"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="69dp" 
    android:id="@+id/RowImageView" 
    android:src="@drawable/img" 
    android:layout_margin="5dp" /> 

<TextView 
    android:layout_width="300dp" 
    android:layout_height="80dp" 
    android:text="thisIsATestText" 
    android:id="@+id/textView" /> 

ответ

0

Попробуйте вместо

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

<ImageView 
android:layout_width="wrap_content" 
android:layout_height="69dp" 
android:id="@+id/RowImageView" 
android:src="@drawable/img" 
android:layout_margin="5dp" /> 

<TextView 
android:layout_width="300dp" 
android:layout_height="80dp" 
android:text="thisIsATestText" 
android:id="@+id/textView" /> 
+0

Благодарим за помощь! – TorbenVerdorben

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal"  android:layout_width="wrap_content" 
    android:minHeight="80dp" 
    android:minWidth="80dp" 
    android:layout_height="wrap_content" 
    android:weightSum="1"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_weight="0.4" 
     android:layout_height="wrap_content" 
     android:minHeight="69dp" 
     android:id="@+id/RowImageView" 
     android:src="@drawable/img" 
     android:layout_margin="5dp" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_weight="0.6" 
     android:layout_height="wrap_content" 
     android:minHeight="80dp" 
     android:text="thisIsATestText" 
     android:id="@+id/textView" /> 
    </LinearLayout> 
+1

Спасибо за помощь! – TorbenVerdorben

1

Ваш ImageView, вероятно, слишком большой, так что она перекрывает ваш TextView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:weightSum="1"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_weight="0.6" 
     android:layout_height="69dp" 
     android:id="@+id/RowImageView" 
     android:src="@drawable/img" 
     android:layout_margin="5dp" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_weight="0.4" 
     android:layout_height="80dp" 
     android:text="thisIsATestText" 
     android:id="@+id/textView" /> 

Если вы хотите использовать layout_weight, чтобы определить ширину ваших элементов, вы не должны использовать wrap_content. Обратите внимание, что вы использовали weightSum="1", чтобы определить полную ширину вашего LinearLayout. Все в порядке. Это означает, что дети этого макета должны иметь вес, равный 1 вместе. Как вы могли заметить, я использовал 0.6 для ImageView и 0.4 для TextView. Также очень важно использовать layout_width="0dp", чтобы вес работал нормально.

+1

Спасибо за помощь! – TorbenVerdorben