android listview适合屏幕

时间:2016-01-09 17:13:56

标签: android

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/footer"
    android:layout_alignParentEnd="true"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:ignore="InconsistentLayout">

    <ListView
        android:id="@+id/contacts_list"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_above="@+id/footer"
        android:layout_alignParentTop="true">

    </ListView>

</android.support.v4.widget.SwipeRefreshLayout>

上面的代码列表视图在角落周围有一些空间。我需要设置我的列表视图以适应screen.could任何一个给出解决方案

2 个答案:

答案 0 :(得分:0)

您正在使用

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

这使得你的layour包装列表视图将有余量,所以要修复它,你只需要将它们设置为0:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/footer"
    android:layout_alignParentEnd="true"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:ignore="InconsistentLayout">

<ListView
    android:id="@+id/contacts_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/footer"
    android:layout_alignParentTop="true">

</ListView>

答案 1 :(得分:0)

只需删除填充

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/footer"
    android:layout_alignParentEnd="true"
    tools:ignore="InconsistentLayout">

    <ListView
        android:id="@+id/contacts_list"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_above="@+id/footer"
        android:layout_alignParentTop="true">

    </ListView>

</android.support.v4.widget.SwipeRefreshLayout>