2012-07-26 152 views
0

我正在开发和android应用程序,其中我创建了一个包含ImageView和TextView的ListActivity。还可以拖放这些对象以便移动它们。我现在想要做的是在屏幕底部有一个按钮,而不是列表。将按钮添加到ListActivity

由于用户滚动按钮将始终停留在那里。我发现这个link,但当我做了这个链接建议没有按钮确实出现,而是我有一个巨大的空白,占据了屏幕的四分之一。任何人都可以指向正确的方向吗?

好了,所以这里是设置为ListActivity

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<DragNDrop.DragNDropListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    </DragNDrop.DragNDropListView> 
</LinearLayout> 

希望.xml文件,它可以帮助

回答

4

你的观点应该是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
<Button 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:text="Button" 
    android:layout_centerHorizontal="true"/> 
<ListView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@+id/btn"/> 
</RelativeLayout> 

填充ListView与数据并看到按钮将在其位置,但列表正在滚动。

+0

好吧,我我已经做了这个,因为我也在我的问题中说过。我的问题虽然静立不动。现在我在屏幕左上角有一个按钮,所有数据只显示在列表的第一行,整个屏幕留空。你认为如果我发布与我的ListActi相关的xml文件会更好VITY? – Libathos 2012-07-26 11:59:45

+0

是的..你更好地发布你的代码,这将是很容易任何人了解和解决你的问题。 – AkashG 2012-07-26 12:00:55

+0

好吧,你是对的我一直在使用linearLyaout整个时间犯了一个错误,我付出了更多的关注,它的工作很多! – Libathos 2012-07-26 12:30:39

0

我认为ListActivity是一个不好的做法。 您需要做的就是将活动从ListActivity更改为活动。在布局文件,请执行下列操作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_contant" 
    android:orientation="horizontal"> 
<DragNDrop.DragNDropListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_contant"> 
</DragNDrop.DragNDropListView> 
<Button 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button"/> 
</LinearLayout> 

在上创建您可以通过获取列表参考:

ListView lv = (ListView)findViewById(R.id.list); 

为了使按钮点击,用户OnClickListener