2012-06-30 8 views
0

이것은 간단 해 보이지만 Google 검색 인내심을 소진했습니다.LinearLayout 하위가있는 RelativeLayout 부모를 채우십시오.

나는 두 개의 하위가 나란히있는 RelativeLayout을 가지고 있는데, 두 LinearLayouts의 높이에 상관없이 둘 다 세로로 부모를 채우기를 원합니다. 이 행은 ListView 행으로 사용되고 @ id/item_left 아래의 내용은 일반적으로 오른쪽에있는 것보다 짧습니다.

배경 드로어 블이 전체 행을 채우지 않습니다.

양면 작성에 대한 아이디어가 있으십니까?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:id="@+id/item_left" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:paddingRight="2dp" 
     android:paddingLeft="2dp" 
     android:background="@drawable/item_left" 
     android:orientation="vertical"> 
     <TextView android:id="@+id/time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/item_left_text" 
      android:text="" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@color/item_right_background" 
     android:layout_toRightOf="@id/item_left">   
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/item_right_text" 
      android:text="Row1" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/item_right_text" 
      android:text="Row2" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/item_right_text" 
      android:text="Row3" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

당신이 반 반을 부여 할 수 있습니다 첫 번째 텍스트 뷰의 텍스트를 변경합니다 색상을 변경 양쪽 너비? –

+0

너비는 콘텐츠와 함께 흐르게됩니다. 왼쪽은 오른쪽보다 폭이 훨씬 작습니다. – Kirk

+0

콘텐츠 당 왼쪽 너비가 필요하지만 두 LL 모두 부모를 채워야합니까? –

답변

1

것은 죄송합니다 ....이 코드를 시도하지만 난 그렇게 충격이 때

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="fill_parent" 
    android:background="#ffffffff" android:weightSum="1"> 

    <LinearLayout android:id="@+id/item_left" 
     android:layout_width="wrap_content" android:layout_height="fill_parent" 
     android:paddingRight="2dp" android:paddingLeft="2dp" 
     android:background="#ff0000ff" android:orientation="vertical" > 
     <TextView android:id="@+id/time" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textColor="#ff555555" 
      android:text="sdfdsf s ada d a asd sad sad" /> 
    </LinearLayout> 

    <LinearLayout android:layout_width="wrap_content" 
     android:layout_height="match_parent" android:orientation="vertical" 
     android:background="#ffff0000" 
     android:layout_weight="1" > 
     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textColor="#ff555555" 
      android:text="Row1" /> 

     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textColor="#ff00ff00" 
      android:text="Row2" /> 

     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:textColor="#ff00ff00" 
      android:text="Row3" /> 
    </LinearLayout> 


</LinearLayout> 
+0

답장을 보내 주셔서 감사합니다. 그러나'layout_toRightOf'는'LinearLayout'의 자식에 대해 존재하지 않으며 또한'layout_weight'는'RelativeLayout'의 자식에 대해서 존재하지 않습니다 – Kirk

+0

하지만, android : layout_toRightOf가 필요하지 않습니다. LinearLayout은 자동으로 추가됩니다. 오른쪽 안드로이드 : orientation = "horizontal"(기본 설정) –

+1

그래, 맞아. 그게 잘 됐어. – Kirk

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/layout1" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="#FF0000"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="helloooooooooooooo" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@id/layout1" 
     android:background="#0000FF" 

> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Row1" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Row2" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Row3" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

답장을 보내 주셔서 감사합니다. 나는 이것을 시도하고 그것은 한 줄의 전체 화면을 만들지 만 아무것도 표시하지 않는다. – Kirk

관련 문제