2011-10-18 3 views
2

안녕하세요!RelativeLayout은 목록보기 항목과 다르게 동작합니다.

저는 수 시간의 조사와 수 시간 후에 설명이없는 성가신 레이아웃 문제에 직면하고 있습니다. 여기에 제시된 축소 된 테스트 케이스를 만들었습니다.

간단한 목록 항목 레이아웃이 있습니다.

list item http://www.freeimagehosting.net/4075a.jpg

lis item image link

XML :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="96dp"> 

<TextView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> 

<TextView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:text="TextView" 
    android:id="@+id/textView2" android:layout_alignParentTop="true" /> 

<ImageView 
    android:layout_width="10dp" 
    android:layout_height="match_parent" 
    android:id="@+id/imageView1" 
    android:src="@drawable/errorindicator" 
    android:layout_below="@id/textView2" /> 

</RelativeLayout> 

errorindicator 당신이 왼쪽에있는 이미지를 볼 수있는 빨간색 사각형입니다. xml은 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?> 
    <shape shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/ControllingConflictColor" /> 
    <padding android:left="0dp" android:top="0dp" 
     android:right="0dp" android:bottom="0dp" /> 
    </shape> 

설명 된 목록 항목 레이아웃이 예상대로 작동합니다.

이제 목록 항목을 위의 설명 된대로으로 채우려고합니다. 그 결과는 다음과 같습니다

list view with list items http://www.freeimagehosting.net/4cc4b.jpg

list view image link

대응하는 XML : 당신은 이미지를 볼 수있는

<?xml version="1.0" encoding="utf-8"?> 
    <ListView android:id="@+id/listView1" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
     <!-- Preview: [email protected]/test --> 
    </ListView> 

, 빨간색 사각형은이에 부모의 일치하지 않는 높이만큼 더 이상. 이미지는 디자이너에서 만들어 지지만 동일한 효과는 에뮬레이터와 장치에도 적용됩니다. API 레벨 8에 대해 개발 중입니다.

** 설명 된 레이아웃이 목록보기에서 예상대로 작동하지 않는 이유를 누군가 설명 할 수 있다면 좋겠습니다. 셰이프 드로어 블의 동작이 다른 이유는 무엇입니까? **

은 당신의 시간 :

편집을 주셔서 감사합니다 : 나 이미지를 삽입 문제가, 내가 대신 죄송 링크를 사용 ( 편집 :. 추가 XML 당김 태그를

편집 : 예제를 훨씬 더 쉽게 만들 수도 있습니다. 실제 레이아웃과 약간의 유사점이 있기 때문에 두 개의 텍스트 뷰를 포함 시켰습니다. 예제에서 두 개의 텍스트 뷰를 제거 할 수는 있지만 문제는 여전히 남아 있습니다. 레이아웃이 목록보기에서 사용되는 경우 이미지보기가 정의 된 부모 높이와 일치하지 않습니다.

+0

원하는 레이아웃 디자인은 무엇입니까? – Venky

+0

모든 텍스트 뷰의 아래 라인이 필요합니까? – Venky

+0

첫 번째 링크 된 이미지에서 원하는 디자인을 볼 수 있습니다. 문제는 목록 뷰에서 설명 된 상대 레이아웃을 사용하면 빨간색 모양 드로어 블 동작이 다르게 동작한다는 것입니다. –

답변

0

, 나는 내 개인의 상황에 맞는 다른 방법을 갔다.당신은 PNG로 자산을 한 경우

난 당신이 다음 수 ...

0

또한 RelativeLayout을 사용하여 완료하기가 어렵습니다. 행 XML에 대해이 레이아웃을 시도해보십시오. LinearLayout을 사용합니다. 난 내 원하는 동작이주고 레이아웃 매니저 불가능 추측 때문에

<?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:orientation="vertical"> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView" 
     android:id="@+id/textView2" 
     android:layout_alignParentTop="true" /> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout android:layout_width="10dip" 
      android:layout_height="fill_parent" 
      android:background="@drawable/errorindicator"/>  
     <TextView android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:text="TextView" android:layout_weight="1.0" 
      android:id="@+id/textView1" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:gravity="center"/> 
    </LinearLayout> 
</LinearLayout> 
+0

답변 해 주셔서 감사합니다. blessenm. 문제 설명은 목록 뷰에서 설명 된 상대 레이아웃을 사용하는 경우 모양 드로어 블이 부모 높이와 일치하지 않는다는 것을 보여주는 축소 된 예제입니다. 따라서 같은 레이아웃의 동작은 목록보기에서 사용되는지 여부와는 다릅니다. 제 예제에서와 같은 효과를 시각적으로 얻을 수있는 여러 가지 방법이 있지만 레이아웃이 상대적 레이아웃보다 훨씬 간단하고 효율적이라는 것을 알고 있습니다. 문제는 더 많습니다. 왜 모양 드로어 블이 다른 동작을하는 것입니까? 나는 목록보기의 레이아웃 과정에서 다른 뭔가가 있어야한다고 생각합니다 ... –

+0

크기가 드로어 블 모양으로 지정되었을 때 나타났습니다. 나에게도 이상하게 보일 수 있습니다. – blessenm

+0

대단히 감사합니다! 제 질문을 편집하고 텍스트보기가 관련이 없다는 점을 지적하십시오. –

0

RelativeLayout의의 된 onDraw 메소드를 오버라이드 (override)이 빨간색 사각형 자신 페인트 (완료 레이아웃 처리 후와 높이가 설정) 한 9 패치하고 RelativeLayout의 배경으로 추가하십시오

+0

이 제안을 해주셔서 감사합니다. 나는 그것을 시도하지 않았지만, 해결 방법 (심지어 9- 패치가 없어도 기존의 드로어 블이 가능함)으로도 작동 할 것이라고 상상할 수 있습니다. 그러나 그것은 여전히 ​​내 질문에 대답하지 않는다; –

관련 문제