Android ListView行布局忽略填充

Cor*_*ton 4 java android listview android-layout baseadapter

我确信这是一个简单的东西,我忽略了但我无法理解.我有一个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>
Run Code Online (Sandbox Code Playgroud)

但是填充被忽略了.如果我使用嵌套的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>
Run Code Online (Sandbox Code Playgroud)

第一个布局在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>
Run Code Online (Sandbox Code Playgroud)

包含的布局:

<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>
Run Code Online (Sandbox Code Playgroud)

这是布局如何膨胀(我最初提供的是一个空父,并认为这是问题,但它似乎不是:

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

    if (view == null) {
        view = _layoutInflater.inflate(_layoutResourceId, parent, false);
        ...
Run Code Online (Sandbox Code Playgroud)

pt1*_*123 5

当我删除代码以设置padding工作的背景时,我遇到了同样的问题.

编辑:找出导致它的原因,它是9个补丁图像中的填充线,我想如果你把它从图纸中删除它会在布局xml中使用填充.但它实际上然后使用可拉伸区域作为可绘制区域.

如果未包含填充线,则Android使用左线和顶线来定义此可绘制区域,从而有效地定义填充.

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