开发者

layout gets chopped off in a lower resolution screen

开发者 https://www.devze.com 2023-03-29 01:30 出处:网络
In my android app, I have a RelativeLayout with listview and 4 buttons in the bottom. Selecting any item in a listview will make four hidden buttons visible. I have followed the best practices from th

In my android app, I have a RelativeLayout with listview and 4 buttons in the bottom. Selecting any item in a listview will make four hidden buttons visible. I have followed the best practices from the http://developer.android.com/guide/practices/screens_support.html. It works fine in the emulator for WVGA800 and in the actual device. I was in a process of testing my app on different screen size. Looks like for QVGA(240x320), the buttons in the bottom gets chopped off. Here is the 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&开发者_运维技巧gt; 
  <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>

Also, I want the listview to occupy a fixed length in the layout. Eg: atleast 70% of the screen, so that the length of the listview is not dependent on the items in the listview.

Thanks in advance


Change all units in the xml to dp. Then adjust the controls. Else you'll have to use scrollview as the parent.


I have some modifications to ur layout. This might work.

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

Try not to use exact width and heights as it might not work on all phones.

0

精彩评论

暂无评论...
验证码 换一张
取 消