2011-08-18 89 views
0

在我的android应用程序中,我有一个带有listview和4个按钮的RelativeLayout。在列表视图中选择任何项目将使四个隐藏的按钮可见。我遵循了http://developer.android.com/guide/practices/screens_support.html的最佳做法。它在WVGA800的仿真器和实际设备中工作正常。我正在测试不同屏幕尺寸的应用程序。看起来像QVGA(240x320),底部的按钮被砍掉。 这里是XML布局在较低分辨率屏幕上被砍掉

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/listViewrelativeLayout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > 
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/info_tv_id" android:textSize="10sp" android:layout_marginLeft="10dip"></TextView> 
    <ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:choiceMode="singleChoice" android:layout_marginTop="25dip" android:layout_below="@id/info_tv_id"> 
    </ListView> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:layout_alignParentBottom="true" android:id="@+id/relativekeybuttons" android:layout_below="@+id/listView1" android:visibility="gone">" 
       <Button android:id="@+id/setasdefault" android:text="@string/default_btn_text" android:layout_marginTop="10dip" 
       android:layout_height="50sp" android:layout_width="75sp"> 
       </Button> 
       <Button android:id="@+id/changepassphrase" android:layout_marginTop="10dip" android:text="@string/passphrase_btn_text" android:layout_width="75sp" android:layout_height="50sp" 
       android:layout_toRightOf="@+id/setasdefault"></Button> 
       <Button android:id="@+id/rename" android:text="@string/rename_btn_text" android:layout_marginTop="10dip" android:layout_width="75sp" android:layout_height="50sp" 
       android:layout_toRightOf="@+id/changepassphrase"></Button> 
       <Button android:id="@+id/delete" android:layout_width="75sp" android:layout_marginTop="10dip" android:layout_height="50sp" android:text="@string/delete_btn_text" 
       android:layout_toRightOf="@+id/rename"></Button>    
    </RelativeLayout>  
</RelativeLayout> 

另外,我想列表视图占据布局固定长度。例如:至少70%的屏幕,以便列表视图的长度不依赖于列表视图中的项目。

在此先感谢

+0

你确定他们都属于相同的广义密度** hdpi **。如果没有,你可以尝试一个新的文件夹的布局。 – Samuel

回答

0

将xml中的所有单位更改为dp。然后调整控件。否则,你将不得不使用scrollview作为父项。

0

我有一些修改你的布局。这可能工作。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:id="@+id/listViewrelativeLayout" 
    android:orientation="vertical"> 
    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" 
     android:id="@+id/info_tv_id" android:text="Click Me" android:textSize="18sp" 
     android:layout_marginLeft="10dip" android:gravity="center"/> 
    <FrameLayout android:layout_width="fill_parent" android:layout_height="0dip" 
     android:layout_weight="1.0"> 
     <ListView android:id="@+id/listView1" android:layout_width="fill_parent" 
      android:layout_height="fill_parent" android:choiceMode="singleChoice" 
      android:layout_below="@id/info_tv_id"/> 
     <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:id="@+id/relativekeybuttons" android:orientation="horizontal" 
      android:layout_gravity="bottom" android:visibility="gone"> 
      <Button android:layout_width="0dip" android:layout_height="wrap_content" 
       android:layout_weight="1.0" android:text="Default" android:layout_marginLeft="1dip" 
       android:textSize="11sp"/> 
      <Button android:layout_width="0dip" android:layout_height="wrap_content" 
       android:layout_weight="1.0" android:text="Passphrase" 
       android:textSize="11sp"/> 
      <Button android:layout_width="0dip" android:layout_height="wrap_content" 
       android:layout_weight="1.0" android:text="Rename" 
       android:textSize="11sp"/> 
      <Button android:layout_width="0dip" android:layout_height="wrap_content" 
       android:layout_weight="1.0" android:text="Delete" android:layout_marginRight="1dip" 
       android:textSize="11sp"/> 
     </LinearLayout> 
    </FrameLayout> 
</LinearLayout> 

尽量不要使用确切的宽度和高度,因为它可能不适用于所有手机。