2013-01-15 68 views
0

我已經創建了一個佈局文件。其中包含其他佈局。 它也有一個列表視圖。我給予了固定的高度。 其在我的屏幕上工作正常,但當我們用它來其他屏幕尺寸 其未顯示完整。它如何適用於所有規模的設備。下面給出了代碼 。修復android的listview大小到一個特定的長度

<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> 
+1

嘗試使用機器人:體重,讓您的列表視圖可根據您的屏幕尺寸的大小。 – Venky

回答

0

你有沒有predecide根據設備屏幕大小的行,然後計算出每個高度row.you不應該明確給出了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; 
    }