2012-07-26 153 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