2010-12-21 41 views
0

我有一个如下所示的布局。 我的问题是,在小屏幕上,视图底部的按钮被推出了用户的视图。我认为我可以通过将整个布局封装在ScrollView中来轻松解决这个问题,但是我知道这不是一个可行的解决方案,因为在我的布局中有一个ListView。需要关于如何改善小屏幕布局的输入

那么,关于如何改变这种布局的任何建议?我的主要问题是我有一个适配器连接到ListView,我不确定是否可以重做布局并使用适配器。想到任何人?

问候 丹尼尔

顺便说一句,我的here's布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    style="@style/defaultBackground" 
    > 
    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:orientation="horizontal" 
     android:paddingBottom="10dip" 
     > 
     <TextView 
      android:id="@+id/roundInfo" 
      android:layout_width="wrap_content" 
      android:layout_height="20dip" android:textColor="#000" 
      /> 
     <TextView 
      android:id="@+id/balance" 
      android:layout_width="fill_parent" 
      android:layout_height="20dip" 
      android:gravity="right" 
      android:textColor="#000" 
      /> 
    </LinearLayout> 

    <ListView 
     android:id="@android:id/list" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:textSize="10sp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:listSelector="@drawable/custom_row" 
     android:background="@drawable/custom_listview" 
     android:dividerHeight="0dip" 
     android:cacheColorHint="#FFFFFF" 
     android:fadingEdge="none" 
     android:divider="#FFFFFF" 
     /> 
    <TextView 
     android:id="@+id/gameCost" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/gameCost_not_finished" 
     android:textColor="#000" \ 
     android:paddingTop="10dip" 
     /> 
    <Button 
     android:id="@+id/update_button" 
     android:text="@string/placebet_button" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     style="@style/whiteText" 
     android:background="@drawable/custom_button" 
     /> 
</LinearLayout> 

回答

0

对于这种情况,你应该使用的RelativeLayout代替的LinearLayout的。尝试是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    style="@style/defaultBackground" 
    > 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignParentTop="true" 
     android:orientation="horizontal" 
     android:paddingBottom="10dip" 
     > 
     <TextView 
      android:id="@+id/roundInfo" 
      android:layout_width="wrap_content" 
      android:layout_height="20dip" android:textColor="#000" 
      /> 
     <TextView 
      android:id="@+id/balance" 
      android:layout_width="fill_parent" 
      android:layout_height="20dip" 
      android:gravity="right" 
      android:textColor="#000" 
      /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" 
     > 
     <TextView 
      android:id="@+id/gameCost" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/gameCost_not_finished" 
      android:textColor="#000" 
      android:paddingTop="10dip" 
      /> 
     <Button 
      android:id="@+id/update_button" 
      android:text="@string/placebet_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      style="@style/whiteText" 
      android:background="@drawable/custom_button" 
      /> 
    </LinearLayout> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:textSize="10sp" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/footer" 
     android:layout_below="@id/header" 
     android:listSelector="@drawable/custom_row" 
     android:background="@drawable/custom_listview" 
     android:dividerHeight="0dip" 
     android:cacheColorHint="#FFFFFF" 
     android:fadingEdge="none" 
     android:divider="#FFFFFF" 
     /> 
</RelativeLayout> 

基本上,改变你的根布局为RelativeLayout的,和你的内容分成三个部分:头,身,尾。在水平LinearLayout中保持标题原样,并将其设置为alignParentTop。由于它只设置为wrap_content,所以我们不必担心重量或任何事情。然后,将应该放在底部的其他固定项目(gameCost文本和placeBet按钮)放置到用作页脚的垂直LinearLayout中。将其设置为alignParentBottom。最后,用fill_parent的高度声明你的ListView。这将占用剩余空间,但为了将其保留在页眉和页脚的范围内,我们添加layout_above和layout_below参数。希望这可以帮助!

+0

非常感谢你的回答!我想知道如果我的用户在使用RelativeLayout解决方案时认为ListView太小,我是否可以做任何事情? – Daniel 2010-12-21 20:56:22