0

我创建了一个布局文件。里面还有其他布局。其中还有一个列表视图。我给它固定高度。它在我的屏幕上工作正常,但是当我们将它用于其他屏幕尺寸时,它没有完全显示。它如何适用于所有尺寸的设备。代码如下。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
     android:background="@drawable/bg" >

    <include
        android:id="@+id/mainScreenHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/main_screen_header" />


    <include
        android:id="@+id/mainScreenListHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mainScreenHeader"
        layout="@layout/main_screen_list_header" >
    </include>

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="270dp"
        android:layout_below="@+id/mainScreenListHeader"
        android:cacheColorHint="#00000000"
        android:drawSelectorOnTop="false" />

     <include
        android:id="@+id/mainScreenFilterClient"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/list"
        android:layout_marginTop="10dp"
        layout="@layout/main_screen_filter_client" >
    </include>

    <include
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mainScreenFilterClient"
        android:layout_marginTop="10dp"
        layout="@layout/footer" >
    </include>
    </RelativeLayout>
4

1 回答 1

0

您必须根据设备屏幕尺寸预先确定行数,然后计算每行的高度。您不应明确给出 android:layout_height="270dp"。您可以获得屏幕的高度并确定列表视图中的行数可以参考:

    private int retrieveDimensions() {
        int noOfRows= 0;
        int screenSize = getResources().getConfiguration().screenLayout &
                Configuration.SCREENLAYOUT_SIZE_MASK;

        switch(screenSize) {
        case Configuration.SCREENLAYOUT_SIZE_LARGE:
        case Configuration.SCREENLAYOUT_SIZE_XLARGE:
            noOfRows= 5;
            break;
        case Configuration.SCREENLAYOUT_SIZE_NORMAL:
            noOfRows= 4;
            break;
        case Configuration.SCREENLAYOUT_SIZE_SMALL:
            noOfRows= 3;
            break;
    }
于 2013-01-15T08:32:35.547 回答