2014-07-22 2 views
0

ListView의 목록 항목에 대해 다음과 같은 레이아웃을 만들려고합니다. 이상적으로 나는 5 개의 텍스트보기가 다음과 같이 배열 된 레이아웃을 원할 것입니다. 기본적으로 위쪽 행에 두 개의 TextView가 고정되어 있고 나머지 두 개는 똑같이 나머지 공간이 분할되어 있습니다. 하나의 텍스트 뷰가 남은 공간을 채우는 방법에 대한 제안을 발견했지만 두 개의 텍스트 뷰가 공간을 균등하게 나눌 수있는 방법에 대해서는 아무것도 없습니다. 오 TextViews의 결과 세트는 레이아웃 항목2 남은 공간을 똑같이 채우는 TextViews

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="6dip"> 

    <TextView 
     android:id = "@+id/s1" 
     android:layout_width="50dip" 
     android:layout_height = "50dip" 
     android:text="what" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
    android:gravity="left" 
     /> 
    <TextView 
     android:id = "@+id/t1" 
     android:layout_width="fill_parent" 
     android:layout_height = "50dip" 
     android:layout_toRightOf="@id/s1" 
     android:text="why" 
     android:layout_alignParentTop="true" 
     /> 
    <TextView 
     android:id = "@+id/t2" 
     android:layout_width="fill_parent" 
     android:layout_height = "50dip" 
     android:layout_toRightOf="@id/t1" 
     android:text="why" 
     android:layout_alignParentTop="true" 
     /> 
    <TextView 
     android:id = "@+id/s2" 
     android:layout_width="50dip" 
     android:layout_height = "50dip" 
     android:layout_toRightOf="@id/t2" 
     android:text="what" 
     android:gravity="right" 
     android:layout_alignParentTop="true" 

     /> 
    <TextView 
     android:id = "@+id/bottom" 
     android:layout_width="fill_parent" 
     android:layout_height = "wrap_content" 
     android:layout_below="@id/s1" 
     android:text="what" 
     android:gravity="center" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 

     /> 
    </RelativeLayout> 
+0

이's1'와's2' 뷰는 항상 고정 폭 (50dip)을해야합니다합니까 취해야 할 것은 예 -?이 될 것입니다 추가 LinearLayout을 사용하여 'RelativeLayout'만으로 원하는 것을 얻을 수 있습니다. –

+0

가중치가있는 LinearLayout – zgc7009

+0

무엇을 의미하는지 생각해 볼 수 있습니까? 독서로 이해하기가 조금 어렵습니다. 이미지가 정말 도움이 될 것입니다 –

답변

0

LinearLayout와 부모 RelativeLayout 교체를 작성해야합니다 (또는 추가 LinearLayout를 추가 할 수없는 경우 다음이 동일 차지하려는 모든 TextViewsandroid:layout_weight="1"를 추가 그것으로 모든 TextViews를 넣어 . 나머지 공간의 부분

+0

이것은 RelativeLayout에 아무런 영향을 미치지 않습니다 –

+0

맞습니다. 루트 레이아웃 유형을 확인하지 않았습니다. –

0

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:padding="6dip"> 

<TextView 
    android:id = "@+id/s1" 
    android:layout_width="50dip" 
    android:layout_height = "50dip" 
    android:text="what" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:gravity="left" /> 

<TextView 
    android:id = "@+id/s2" 
    android:layout_width="50dip" 
    android:layout_height = "50dip" 
    android:text="what" 
    android:gravity="right" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true"/> 

<LinearLayout 
    android:layout_height="50dip" 
    android:layout_width="match_parent" 
    android:layout_toRightOf="@id/s1" 
    android:layout_toLeftOf="@id/s2" 
    android:layout_alignParentTop="true" 
    android:orientation="horizontal" > 

    <TextView 
     android:id = "@+id/t1" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height = "match_parent" 
     android:text="why"/> 

    <TextView 
     android:id = "@+id/t2" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height = "match_parent" 
     android:text="why" /> 

</LinearLayout> 

<TextView 
    android:id = "@+id/bottom" 
    android:layout_width="fill_parent" 
    android:layout_height = "wrap_content" 
    android:layout_below="@id/s1" 
    android:text="what" 
    android:gravity="center" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" /> 
</RelativeLayout> 
관련 문제