ListView의 Item으로 아래와 같은 layout으로 TextView 3개를 넣었습니다. 문자열이 한 줄일 때는 문제가 없는 데 2줄 이상이 되면 TextView의 높이가 줄어 드는 데, 이유가 뭘까요?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:background="#CDC9A5"
>
<TextView
android:layout_width="50dp"
android:layout_height="70dp"
android:paddingLeft="3dp"
android:gravity="left|center_vertical"
android:id="@+id/text_message_number"
android:background="#FFFFFF"
android:textSize="16sp"
/>
<TextView
android:layout_width="140dp"
android:layout_height="70dp"
android:gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:id="@+id/text_message_date"
android:background="#FFFFFF"
android:textSize="16sp"
/>
<TextView
android:layout_width="150dp"
android:layout_height="70dp"
android:paddingLeft="3dp"
android:gravity="left|center_vertical"
android:layout_marginLeft="5dp"
android:id="@+id/text_message_content"
android:background="#FFFFFF"
android:singleLine="true"
android:textSize="16sp"
/>
</LinearLayout>
android:layout_weight 를 이용하세요. 고정적 폭과 높이 dp 값은 되도록 피하는게 좋습니다.
뭐 대충 이런식으로요. 그럼 text 길이만큼 알아서 위의 Hierachy가 높이를 잘 감싸줍니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CDC9A5"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:id="@+id/text_message_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#FFFFFF"
android:gravity="left|center_vertical"
android:paddingLeft="3dp"
android:textSize="16sp" />
<TextView
android:id="@+id/text_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="2"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:textSize="16sp" />
<TextView
android:id="@+id/text_message_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="2"
android:background="#FFFFFF"
android:gravity="left|center_vertical"
android:paddingLeft="3dp"
android:singleLine="true"
android:textSize="16sp" />
</LinearLayout>