2010-04-29 2 views
5

현재 프로젝트에 대한 작은 업데이트를하고 있으며 목록보기에서 Relative_Layout 및 fill_parent에 문제가 있습니다. 각 행의 두 섹션 사이에 구분선을 삽입하려고합니다. 이는 기본 다이얼러의 호출 로그에있는 구분선과 같습니다. 그들이 안드로이드 소스 코드를 어떻게 체크했는지 확인해 보았지만 솔루션을 복제 할 때 문제가 발생했습니다.안드로이드 RelativeLayout fill_parent 예기치 않은 동작으로 다양한 행 높이를 갖는 ListView

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" 
android:layout_width="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:padding="10dip" 
android:layout_height="fill_parent" 
android:maxHeight="64dip" 
android:minHeight="?android:attr/listPreferredItemHeight"> 
<ImageView android:id="@+id/infoimage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:src="@drawable/info_icon_big" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true"/> 
<View android:id="@+id/divider" 
    android:background="@drawable/divider_vertical_dark" 
    android:layout_marginLeft="11dip" 
    android:layout_toLeftOf="@+id/infoimage" 
    android:layout_width="1px" 
    android:layout_height="fill_parent" 
    android:layout_marginTop="5dip" 
    android:layout_marginBottom="5dip" 
    android:layout_marginRight="4dip"/> 
<TextView android:id="@+id/TextView01" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_toRightOf="@+id/ImageView01" 
    android:layout_toLeftOf="@+id/divider" 
    android:gravity="left|center_vertical" 
    android:layout_marginLeft="4dip" 
    android:layout_marginRight="4dip"/> 
<ImageView android:id="@+id/ImageView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/bborder" 
    android:layout_centerVertical="true"/> 
</RelativeLayout> 

내가 직면하고있어 문제는 각 행은 다양한 높이 (ImageView01)의 축소판을 가지고 있다는 것입니다 : 시작하려면

, 여기 내 행 항목 레이아웃입니다. RelativeLayout의 layout_height 속성을 fill_parent로 설정하면 구분선이 행을 채우도록 세로로 배율을 조정하지 않습니다 (단 1px 점 만 남음). layout_height를 "android : attr/listPreferredItemHeight"로 설정하면 구분선이 행을 채우지 만 축소판은 축소됩니다. 어댑터의 getView() 메소드에서 일부 디버깅을했는데 행의 높이가 적절하면 구분선의 높이가 올바르게 설정되지 않은 것으로 보입니다.

public View getView(int position, View view, ViewGroup parent) { 
      if (view == null) { 
       view = inflater.inflate(R.layout.tag_list_item, parent, false); 
      } 

방법의 나머지는 단순히 행에 대한 적절한 텍스트 및 이미지를 설정한다 : 여기서

는의 getView() 메소드의 일부이다. inflater = LayoutInflater.from(context);

나는 필수적인 뭔가를 놓치고 있습니까 :

또한, 내가 가진 어댑터의 생성자에서 인플레이터 객체를 생성? 아니면 fill_parent가 동적 인 높이에서만 작동하지 않습니까?

답변

0

레이아웃에 순환 의존성이 의심됩니다. 행 layout_heightfill_parent으로 설정 하시겠습니까? 행이 가장 큰 하위보기 (이 경우 @id/ImageView01)와 같은 높이가되도록하려면 layout_height="wrap_content"RelativeLayout에 입력해야합니다. 이렇게하면 높이가 이미지에서 행으로 전파 된 다음 layout_height="fill_parent" 인 다른 어린이로 전파됩니다.

+0

답변 해 주셔서 감사합니다. 그러나 구분선은 행을 세로로 채우지 않습니다. 이 동작이 버그인지 아니면 내가 누락 된 다른 것이 있는지 확실하지 않습니다. 다른 아이디어? –

0

호기심이있는 사람에게 적합합니다. 이것은 SDK의 버그 일 수 있습니다. 문제를 해결하려면 고정 된 행 높이로 가야했습니다. 다른 사람이 문제로 실행되는 경우

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout01" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="100dip" android:layout_width="fill_parent"> 
    <RelativeLayout android:id="@+id/Thumbnail" 
     android:layout_alignParentLeft="true" android:paddingLeft="10dip" 
     android:paddingTop="10dip" android:paddingRight="15dip" 
     android:paddingBottom="10dip" android:layout_height="fill_parent" 
     android:layout_width="wrap_content"> 
     <ImageView android:id="@+id/image" 
      android:layout_width="80dip" android:background="@drawable/bborder" 
      android:layout_centerVertical="true" android:adjustViewBounds="true" 
      android:layout_height="80dp" android:cropToPadding="true" /> 
    </RelativeLayout> 
    <View android:id="@+id/divider" android:background="@drawable/divider_light" 
     android:layout_toRightOf="@+id/Thumbnail" android:layout_marginTop="10dip" 
     android:layout_marginBottom="10dip" android:layout_width="1px" 
     android:layout_height="fill_parent" android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" /> 
    <LinearLayout 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:paddingTop="10dp" android:paddingBottom="10dp" 
     android:layout_centerVertical="true" android:orientation="vertical" 
     android:layout_marginLeft="20dip" android:layout_marginRight="10dip" 
     android:layout_toRightOf="@+id/divider"> 
     <TextView android:id="@+id/title" android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:gravity="left|center_vertical" android:maxLines="1" android:singleLine="true" 
      android:ellipsize="end" /> 
     <TextView android:id="@+id/science_name" android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:gravity="left|center_vertical" android:maxLines="1" android:singleLine="true" 
      android:ellipsize="end" android:textStyle="italic" /> 
    </LinearLayout> 
</RelativeLayout> 
6

, 내가 찾은 유일한 방법 (고정 높이가 아닌)가있는 LinearLayout로 전환하는 것입니다 : 이것은 최종 레이아웃 코드입니다. 필자는 LinearLayouts과 RelativeLayouts의 근본적인 차이 때문이라고 추측합니다. Romain Guy가 그것에 대해 this 기사에서 이야기합니다. LinearLayouts는 너비에 대해서는 onMeasure()를 호출하고 RelativeLayouts에서는 높이에 대해 한 번 호출하므로 다른 모든 것이 배치 된 후에는 프로퍼러 높이로 수직 구분선을 채울 수 없습니다. 솔루션은 다음과 같습니다.

<LinearLayout xmlns:... 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 
    <RelativeLayout android:id="@+id/leftContent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     > 
    </RelativeLayout> 
    <View android:id="@+id/divider" 
     android:layout_width="1px" 
     android:layout_height="fill_parent" 
     android:background="@drawable/divider" /> 
    <RelativeLayout android:id="@+id/rightContent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     > 
    </RelativeLayout> 
</LinearLayout> 

RelativeLayout만큼 효율적이지는 않지만 원하는 결과를 얻을 수 있습니다.

관련 문제