2014-06-21 2 views
0

의 중심에서 목록보기 나는 다음과 같은 레이아웃 (Android 4.4)가 있습니다. 내가 뭘 놓치고 있니?안드로이드 상대 레이아웃

enter image description here

의 ListView 항목 레이아웃 :

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:scaleType="fitXY"/> 


    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@+id/label" 
     android:layout_marginTop="40dp" 
     android:textStyle="bold" 
     android:background="@color/list_background" 
    /> 
</LinearLayout> 

편집 : 나는 wrap_content하기 목록보기 폭을 설정하더라도

  1. , 그것은 차이를 만들지 않습니다.

  2. 외부 뷰를 LinearLayout으로 변경해도 도움이되지 않습니다.

+0

그 대신 –

+0

사용 LinearLayout을 중심으로 할 수있는 방법이 없기 때문에 이미 부모의 폭을 일치 –

+0

@Rod_Algonquin이 목록보기 항목 레이아웃 – Jake

답변

2

List Item Layout을 변경하여 뷰를 수평 가운데에 놓아야합니다.

샘플 :

<?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="match_parent" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/labIcon" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:background="@drawable/lawl" 
     android:scaleType="fitXY" /> 

    <TextView 
     android:id="@+id/labName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="40dp" 
     android:text="item1" 
     android:textStyle="bold" /> 

</LinearLayout> 
0

이 문제가 해결되지 않지만,

<ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 

당신은 ListView를의 높이 wrap_content을 사용할 수 없습니다.

이렇게하면 ListView은 항목을 측정하고 어댑터에서 getView()이라고 불러야하는 항목을 가져와야합니다. 이로 인해 getView() 메서드가 비효율적 인 방식으로 여러 번 호출됩니다.

관련 문제