为什么在Listview中向左和向右滑动后仍留有一些空间

时间:2017-04-20 10:39:03

标签: android listview

我在Listview中向两侧滑动它已成功完成,但是当我向任何一侧滑动时,某些空间是空的,我无法找到空间重命名的原因: -

enter image description here

enter image description here

空间在二次布局后重命名。这是我的孩子布局: -

    <?xml version="1.0" encoding="utf-8"?>
<com.octalsoftaware.archi.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:swipe="http://schemas.android.com/tools"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/whitecolor">

    <LinearLayout
        android:id="@+id/delete_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/red_color"
        android:orientation="horizontal"
        android:paddingBottom="@dimen/_10sdp"
        android:paddingLeft="@dimen/_10sdp"
        android:paddingRight="@dimen/_10sdp"
        android:paddingTop="@dimen/_10sdp"
        android:weightSum="3">

        <LinearLayout
            android:id="@+id/ll_charge"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_weight="1">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:src="@drawable/forbidden" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/delete"
                android:textColor="@android:color/white" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_10sdp"
            android:orientation="vertical"
            android:layout_weight="1">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:src="@drawable/forbidden" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/delete"
                android:textColor="@android:color/white" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_10sdp"
            android:orientation="vertical"
            android:layout_weight="1">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:src="@drawable/forbidden" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/delete"
                android:textColor="@android:color/white" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/left_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/red_color"
        android:paddingBottom="@dimen/_10sdp"
        android:paddingLeft="@dimen/_10sdp"
        android:paddingRight="@dimen/_10sdp"
        android:paddingTop="@dimen/_10sdp"
        android:orientation="horizontal"
        android:weightSum="2">

        <LinearLayout
            android:id="@+id/ll_delete"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_weight="1">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:src="@drawable/forbidden" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/delete"
                android:textColor="@android:color/white" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_marginRight="@dimen/_10sdp"
            android:layout_weight="1">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:src="@drawable/forbidden" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/delete"
                android:textColor="@android:color/white" />

        </LinearLayout>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/whitecolor"
        android:orientation="vertical"
        android:padding="@dimen/_10sdp"
        android:visibility="visible">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_toLeftOf="@+id/img_arrow"
            android:orientation="vertical">

            <TextView
                android:id="@+id/txt_settingname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Lee Alexender"
                android:textColor="@color/lightblack"
                android:textSize="@dimen/_15sdp" />


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_5sdp"
                android:orientation="horizontal">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/chargecircle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:src="@drawable/qicircle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:src="@drawable/cameracircle" />

            </LinearLayout>

        </LinearLayout>


        <ImageView
            android:id="@+id/img_arrow"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/arrow" />


    </RelativeLayout>

</com.octalsoftaware.archi.daimajia.swipe.SwipeLayout>

2 个答案:

答案 0 :(得分:0)

您需要在LinearLayout

中删除这些行
android:paddingLeft="@dimen/_10sdp"
android:paddingRight="@dimen/_10sdp"

答案 1 :(得分:0)

  1. 添加FrameLayout作为SwipeLayout
  2. 的直接子项
  3. attribute android:layout_gravity="right"添加到delete_layout
  4. attribute android:layout_gravity="left"添加到left_layout
  5. 试试这个:

    <?xml version="1.0" encoding="utf-8"?>
    <com.octalsoftaware.archi.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:swipe="http://schemas.android.com/tools"
        android:id="@+id/swipe"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/whitecolor">
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:id="@+id/delete_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/red_color"
                android:orientation="horizontal"
                android:paddingBottom="@dimen/_10sdp"
                android:paddingLeft="@dimen/_10sdp"
                android:paddingRight="@dimen/_10sdp"
                android:paddingTop="@dimen/_10sdp"
                android:weightSum="3"
                android:layout_gravity="right">
    
                <LinearLayout
                    android:id="@+id/ll_charge"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_weight="1">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@drawable/forbidden" />
    
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/delete"
                        android:textColor="@android:color/white" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:orientation="vertical"
                    android:layout_weight="1">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@drawable/forbidden" />
    
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/delete"
                        android:textColor="@android:color/white" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:orientation="vertical"
                    android:layout_weight="1">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@drawable/forbidden" />
    
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/delete"
                        android:textColor="@android:color/white" />
    
                </LinearLayout>
            </LinearLayout>
    
            <LinearLayout
                android:id="@+id/left_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/red_color"
                android:paddingBottom="@dimen/_10sdp"
                android:paddingLeft="@dimen/_10sdp"
                android:paddingRight="@dimen/_10sdp"
                android:paddingTop="@dimen/_10sdp"
                android:orientation="horizontal"
                android:weightSum="2"
                android:layout_gravity="left">
    
                <LinearLayout
                    android:id="@+id/ll_delete"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_weight="1">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@drawable/forbidden" />
    
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/delete"
                        android:textColor="@android:color/white" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:layout_weight="1">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@drawable/forbidden" />
    
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/delete"
                        android:textColor="@android:color/white" />
    
                </LinearLayout>
    
            </LinearLayout>
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/whitecolor"
                android:orientation="vertical"
                android:padding="@dimen/_10sdp"
                android:visibility="visible">
    
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_toLeftOf="@+id/img_arrow"
                    android:orientation="vertical">
    
                    <TextView
                        android:id="@+id/txt_settingname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Lee Alexender"
                        android:textColor="@color/lightblack"
                        android:textSize="@dimen/_15sdp" />
    
    
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/_5sdp"
                        android:orientation="horizontal">
    
    
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/chargecircle" />
    
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="@dimen/_10sdp"
                            android:src="@drawable/qicircle" />
    
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="@dimen/_10sdp"
                            android:src="@drawable/cameracircle" />
    
                    </LinearLayout>
                </LinearLayout>
    
                <ImageView
                    android:id="@+id/img_arrow"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/arrow" />
    
            </RelativeLayout>
        </FrameLayout>
    </com.octalsoftaware.archi.daimajia.swipe.SwipeLayout>