Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android:layout#marginLeft不';我不能在API 8中工作_Android_Android Layout - Fatal编程技术网

android:layout#marginLeft不';我不能在API 8中工作

android:layout#marginLeft不';我不能在API 8中工作,android,android-layout,Android,Android Layout,android:layout_marginLeft在4.4.2上运行良好,但在2.2上不起作用 这是截图 下面是row_layout.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="60dp" android:background="@drawa

android:layout_marginLeft在4.4.2上运行良好,但在2.2上不起作用

这是截图

下面是row_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:background="@drawable/row_selector"
    android:paddingLeft="15dp"
    android:paddingRight="15dp" >

    <ImageView
        android:id="@+id/authorImageView"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center_vertical"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:orientation="vertical"

        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent" >

        <TextView
            android:id="@+id/poemNameTextView"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="20dp"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="Çanakkale Şehitlerine"
            android:textColor="@color/author_list_textcolor_selector"
            android:textSize="16dp"
            android:textStyle="bold" />

    </LinearLayout>

</LinearLayout>

尝试在包含
文本视图的
线性布局上设置边距,而不是在
文本视图上设置边距。如果这不起作用,您也可以尝试对
线性布局应用填充

基本上可以尝试以下布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:background="@drawable/row_selector"
    android:paddingLeft="15dp"
    android:paddingRight="15dp" >

    <ImageView
        android:id="@+id/authorImageView"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center_vertical"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:orientation="vertical"

        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_marginLeft="20dp"
        android:layout_height="fill_parent" >

        <TextView
            android:id="@+id/poemNameTextView"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="Çanakkale Şehitlerine"
            android:textColor="@color/author_list_textcolor_selector"
            android:textSize="16dp"
            android:textStyle="bold" />

    </LinearLayout>

</LinearLayout>


在您的情况下,很可能是
线性布局中的页边距行为
,权重在API 8以上的某个点更改。

//尝试这种方式,希望这将帮助您进一步改进代码以显示列表项。
// try this way,hope this will help you for more improvement of your code to show list item.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/row_selector"
    android:padding="15dp"
    android:gravity="center">

    <ImageView
        android:id="@+id/authorImageView"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp">

        <TextView
            android:id="@+id/poemNameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Çanakkale Şehitlerine"
            android:textColor="@color/author_list_textcolor_selector"
            android:textSize="16dp"
            android:textStyle="bold" />
    </LinearLayout>
</LinearLayout>

尝试将边距放在
线性布局上
。您也可以尝试在
线性布局上使用填充,但为什么不起作用呢?问题是什么?很难说,因为我现在无法真正测试它,但通常会尝试在视图层次结构中尽可能地增加边距和填充,有时由于各种原因,边距不起作用。在这种情况下,请尝试使用填充。在您的情况下,很可能是
线性布局
中的页边距行为在API 8以上的某个点更改了权重。@XaverKapeller谢谢,您的建议奏效了。