回答
我認爲i'ts更好,當你第一次使用的LinearLayout與垂直方向,並把一個按鈕,並把一個ListView。在的LinearLayout將您的 「內容包裝」 是這樣的: main.xml中
<?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">
<Button
android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/listView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:entries="@array/list"/>
</LinearLayout>
和字符串數組項:
<string-array name="list">
<item>Entry1</item>
<item>Entry2</item>
<item>Entry3</item>
<item>Entry4</item>
</string-array>
首先,我只是想確認,是Button
始終,即使ListView
滾動的ListView
頂部,該Button
仍然存在或Button
滾動過也
如果是第一種情況,這是很簡單的,J烏斯特垂直LinearLayout
與Button
之前ListView
如果是第二種情況,它是相當複雜的。因爲你不應該在ScrollView
裏面使用ListView
,所以我建議你讓ListView
的第一行成爲一個內部有Button
的自定義視圖。爲了做到這一點,請查看如何擴展BaseAdapter
和LayoutInflate
。
也許這個按鈕不是列表視圖的一部分。 嘗試撥打佈局是這樣的:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
'ListView'餓了高度,並會填充'LinearLayout'中所有可用的高度。 –
可以使用RelativeLayout的做到這一點:
<RelativeLayout android:id="@+id/parentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My Button"
android:alignParentTop = "true"/>
<ListView android:id="@+id/myList"
android:layout_below="@id/btn"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_gravity="top|center_horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
<Button android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Add Alarm"/>
<ListView android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0"></ListView>
</LinearLayout>
這應該給出所需的佈局。
這項工作。但風格不像這個形象 – Rose
你可以嘗試ListView.addHeaderView();
這樣的按鈕將出現在元件上方的ListView控件內。另外,看看這個tutorial。
您可以設計自己的佈局中正在適配器中充氣的按鈕,並將按鈕可見性消除。在適配器中,如果psoition爲0,並且如果爲0,則只能在getview方法中檢查按鈕,否則使按鈕變爲可見。這樣,您在列表頂部有一個按鈕,並且可以滾動。要使按鈕可點擊,只需在getview方法中實現onclick方法。它非常簡單。
- 1. jQuery的 「前」 添加按鈕
- 2. Android如何在listview中添加可點擊的按鈕?
- 3. 帶按鈕的Android ListView
- 4. 如何從listView動態添加按鈕?
- 5. 在ListView中添加關閉按鈕
- 6. Android Widget添加按鈕
- 7. 如何將行添加到listView按鈕在android studio中單擊?
- 8. Android Studio添加EditText輸入到一個ListView與按鈕onClick
- 9. 如何在Android中添加編輯和刪除按鈕到ListView?
- 10. 的Android:重新按下按鈕時動態添加按鈕
- 11. 添加功能的Android按鈕
- 12. 的Android添加標記按鈕點擊
- 13. 如何添加MapView上的按鈕android
- 14. 的Android - ListView的與無線電按鈕
- 15. android listview按鈕控件
- 16. Android - BaseAdapter - XML,ListView,按鈕
- 17. Android - 單選按鈕在listView?
- 18. Android系統按鈕重疊的ListView
- 19. 帶有刪除按鈕的Android ListView
- 20. Android的AsyncTask ListView包含按鈕onClickListener
- 21. 有兩個按鈕的Android listview
- 22. Android編程 - 帶按鈕的ListView
- 23. Android的listview onclicklistener與動態按鈕
- 24. 帶按鈕的ListView
- 25. ListView上的按鈕
- 26. listView中的按鈕
- 27. 按鈕上的ListView
- 28. Android如何在我的自定義ListView上添加一些浮動按鈕?
- 29. 如何在android中添加文本和切換按鈕上方的listView?
- 30. 添加按鈕
可以參考這個[link](http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/) –
[This](https:/ /android.googlesource.com/platform/packages/apps/DeskClock/+/gingerbread-release)是薑餅原始鬧鐘應用程序的源代碼。您可以看到使用的按鈕樣式不是標準樣式。 – danieleds