简体   繁体   中英

android how to set padding around each edge of a listview

I have the following listview. I'd like to set space around the listview so it doesn't fill the whole screen. How can i achieve this.

I've tried every combination of padding and margins on the the listview and the parent relative layout, none seem to have an effect.

Thanks in advance Matt.

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         >


<ListView
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#8fff"
        android:cacheColorHint="#0000"
        android:divider="#700000ff"
        android:dividerHeight="4px" >
    </ListView>

 </RelativeLayout>

.Edit 1

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         >


     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:padding="10dp">

            <ListView
                    android:id="@+id/android:list"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#8fff"
                    android:cacheColorHint="#0000"
                    android:divider="#700000ff"
                    android:dividerHeight="4px" >
                </ListView>

       </RelativeLayout>

     </RelativeLayout>

将您的listview放在另一个布局中,并对该布局进行填充。

android:layout_margin="sizeindp" use this it works for me 它看起来像下面的快照 do you want to achieve this !!!!

Use this..

            <ListView
                android:id="@+id/android:list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#8fff"
                android:cacheColorHint="#0000"
                android:layout_margin="15dp"
                android:padding="10dp"
                android:divider="#700000ff"
                android:dividerHeight="4px" >
            </ListView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM