2012-05-01 3 views
4

이것은 내가 간과하고있는 것이지만 내가 알아낼 수없는 간단한 것이라고 확신합니다. 간단한 레이아웃으로 사용자 지정 어댑터를 사용하는 ListView가 있고 패딩 값이 무시 된 것 같습니다. 다음은 레이아웃을 원하는 방식입니다.Android ListView 패딩을 무시한 행 레이아웃

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/Widget.Layout.ComponentEntry" android:padding="@dimen/preferred_padding"> 
    <include layout="@layout/component_entry_summary" /> 
</LinearLayout> 

하지만 패딩은 무시됩니다. 내포 된 LinearLayout을 사용하면 작동하지만 내부 LinearLayout은 무의미한 것처럼 보입니다. 이 작품은 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/Widget.Layout.ComponentEntry"> 
    <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:padding="@dimen/preferred_padding"> 
     <include layout="@layout/component_entry_summary" /> 
    </LinearLayout> 
</LinearLayout> 

첫 번째 레이아웃은 ListView의 외부에서 작동하므로 난처한 상황입니다.

<style name="Widget"> 
    <item name="android:textAppearance">@style/TextAppearance</item> 
</style> 

<style name="Widget.Layout"> 
    <!-- Empty Style --> 
</style> 

<style name="Widget.Layout.ListViewItem"> 
    <item name="android:background">@drawable/listview_item_background</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:padding">@dimen/preferred_padding</item> 
</style> 

<style name="Widget.Layout.ComponentEntry" parent="Widget.Layout.ListViewItem"> 
    <item name="android:layout_height">@dimen/listview_item_height</item> 
</style> 

그리고 포함 된 레이아웃 :

여기
<merge xmlns:android="http://schemas.android.com/apk/res/android" > 
    <ImageView android:id="@+id/iconImage" 
       android:layout_gravity="center_vertical" 
       android:layout_height="@dimen/icon_size" 
       android:layout_width="@dimen/icon_size" 
       android:scaleType="fitCenter" 
       android:src="@drawable/ic_launcher" /> 

    <LinearLayout android:layout_gravity="center_vertical" 
        android:layout_height="wrap_content" 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:paddingLeft="@dimen/preferred_padding" 
        android:orientation="vertical"> 

     <TextView android:id="@+id/topText" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:paddingLeft="@dimen/preferred_padding" 
        android:singleLine="true" 
        android:text="@string/app_name" 
        android:textColor="@color/header_text_enabled" 
        android:textStyle="bold" /> 

     <TextView android:id="@+id/bottomText" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:ellipsize="marquee" 
        android:marqueeRepeatLimit="marquee_forever" 
        android:paddingLeft="@dimen/preferred_padding" 
        android:singleLine="true" 
        android:text="@string/app_name" 
        android:textColor="@color/header_text_enabled" /> 
    </LinearLayout> 
</merge> 

레이아웃이 (내가 원래 null의 부모를 공급하고 팽창 것으로 생각된다 방법은 여기를 참고로 (또한 패딩을 지정) 사용되는 스타일이다 문제 였지만이 될 것 같지 않습니다. 배경을 제거

public View getView(int position, View view, ViewGroup parent) { 
    ViewHolder viewHolder; 

    if (view == null) { 
     view = _layoutInflater.inflate(_layoutResourceId, parent, false); 
     ... 

답변

3

작업을 시작하기 위해 외부의 LinearLayout에 패딩의 원인이 된 문제가 왜 아직하지만 파고하지 않았 (부분적으로) 적어도 해결되었다.

+1

는 안드로이드 4.1에서 문제가 있었다,하지만 킷 캣과 롤리팝에 perfecly 일 – serine

5

동일한 문제가 발생했습니다. 배경을 설정하기 위해 코드를 제거했을 때 패딩이 효과적이었습니다.

편집 : 원인이 무엇인지 밝혀 내고, 9 패치 이미지의 패딩 라인입니다. 레이아웃에서 x 패딩을 사용하면 도면에서 빠져 나온 것처럼 보입니다. 그러나 실제로 drawable 영역으로도 stretchable 영역을 사용합니다.

안쪽 여백이 포함되어 있지 않으면 안드로이드는 왼쪽 및 위쪽 줄을 사용하여이 여백 영역을 정의하고 효과적으로 여백을 정의합니다. 나 이에 대한

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch