2011-01-20 81 views
0

我有以下布局的XML布局与列表

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:myapp="http://schemas.android.com/apk/res/se.javalia.myDrinks" 
    > 
    <Button android:id="@+id/saveButton" 
     android:text="test test" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <TextView 
      android:id="@+id/android:empty" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/main_no_items" /> 
</LinearLayout> 

一个listactivity现在,我想补充的时候滚动列表是停留在地方列表上方的按钮。 有没有可能?

在此先感谢 罗兰

回答

2

这绝对有可能,只需在XML中的ListView之前添加一个Button即可。如果您的视图变得更加复杂,我会将您的LinearLayout更改为RelativeLayout,然后您可以更轻松地定位元素。

2

是的,只要添加的ListView上面的按钮。

+0

,如果仅在这么简单,这是行不通的。现在我只看到按钮,没有列表。 – Roland 2011-01-20 19:39:24

0

下不起作用:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:myapp="http://schemas.android.com/apk/res/se.javalia.myDrinks" 
    > 
    <Button android:id="@+id/saveButton" android:text="test test" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
    <ListView android:id="@+id/android:list" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
    <TextView android:id="@+id/android:empty" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:text="@string/main_no_items" /> 
</LinearLayout> 

名单在前看不见,唯一可见的是按钮。

+0

我认为这里的问题是ListView上的android:layout_height =“fill_parent”。使其成为“wrap_content”。 – McStretch 2011-01-20 19:47:24

+1

顺便说一句,不要让这个答案,你应该编辑你的原始问题,并通知我们问题已经改变(留下评论)。你不必这样做,但在上面保持一个完整的问题是很好的。谢谢! – McStretch 2011-01-20 19:50:17

1

在你第一次的LinearLayout你应该增加:机器人:方向=“垂直”