0

如何让ListView填充屏幕并同时移动下面的视图直到它到达底部?例如,在下面的图片中,我想让'创建'按钮在添加新元素时向下移动屏幕,然后当按钮到达底部时,ListView开始滚动(创建按钮仍然出现在屏幕上屏幕)。将更多元素添加到ListView时,视图向下移动

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     > 

    <ListView 
      android:id="@+id/galleryList" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center_vertical" 
      android:layout_alignParentTop="true" 
      /> 

    <LinearLayout 
      android:id="@+id/lowerButtonLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="60dp" 
      android:background="#ffa8269f" 
      android:layout_alignParentBottom="true" 
      xmlns:android="http://schemas.android.com/apk/res/android"> 

     <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/button_button_bg_colour" 
       android:onClick="addRow" 
       android:text="Create"/> 
    </LinearLayout> 

</RelativeLayout> 

enter image description here

+0

创建一个自定义xml并将其添加为ListView的页脚。而且您必须将ListView高度设置为fill_parent。 – 2014-09-06 12:19:56

+0

@dpsingh - 希望这可以通过布局完成 – Ian 2014-09-06 12:21:31

+0

另一种方法是在ScrollView中使用ListView。 – 2014-09-06 12:40:37

回答

0

不幸的是,它不能只用XML文件来完成。

最简单的方法是使用2个按钮。一个在你的主布局中,另一个在你的ListView(例如作为页脚视图)。然后根据ListView是否达到特定高度,将一个按钮的可见性设置为View.GONE。 如果您的单元具有相同的高度,则计算非常简单。

请勿在ScrollView内使用ListView。它会毁掉ListView的所有目的(能够回收细胞)。

相关问题