有隻允許垂直滾動的ScrollView和只允許水平滾動的HorizontalScrollView,但兩者都沒有類。這看起來像是Android UI中的一個非常大的缺陷。任何技巧,讓這個?Android - 如何允許水平和垂直滾動
13
A
回答
28
試試這個
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/amortization"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:background="#ffff00">
<TextView
android:text="@string/amortization_1"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_2"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_3"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_4"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_5"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_6"
android:padding="3dip"/>
<TextView
android:text="@string/amortization_7"
android:padding="3dip"/>
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
2
與ImageView的一個例子:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:id="@+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/ImageView01"
android:src="@drawable/pic"
android:isScrollContainer="true"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:adjustViewBounds="true">
</ImageView>
</HorizontalScrollView>
</ScrollView>
來源:http://www.android-spa.com/viewtopic.php?t=3959&highlight=scrollview+vertical+horizontal
+2
恕我直言,一個需要兩個滾動的屏幕根本不舒服(實際上我認爲垂直滾動不是一個好主意),但它起作用。 – 2011-04-24 15:42:16
+0
這是一個比屏幕大得多的遊戲。哥們,謝啦。 – 2011-04-24 15:43:50
1
我發現設置fillViewport
是很重要的,否則滾動條可能會出現在隨機位置而不是在滾動區域的右側/底部:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
</HorizontalScrollView>
</ScrollView>
相關問題
- 1. 滾動水平和垂直
- 2. 允許在tbody中水平和垂直滾動表格
- 3. Android:水平和垂直滾動recyclerview
- 4. Android:水平和垂直滾動recyclerview
- 5. 垂直滾動和水平滾動
- 6. 水平滾動和垂直滾動
- 7. 水平/垂直滾動ListView
- 8. 固定的水平位置,但允許與jQuery垂直滾動
- 9. iframe允許垂直滾動條,但不是水平的
- 10. 水平/垂直滾動
- 11. jquery滾動垂直/水平
- 12. Android垂直滾動ListView水平scrollView
- 13. 垂直滾動和水平滾動的Android
- 14. 在android中垂直滾動和水平滾動的元素
- 15. 垂直滾動的水平滾動條
- 16. 如何在android中水平和垂直滾動表格佈局
- 17. Android ListView如何垂直和水平滾動?
- 18. UIScrollView策略水平和垂直滾動
- 19. malihu水平和垂直滾動
- 20. EditText水平和垂直滾動
- 21. 垂直和水平滾動不工作
- 22. Uiscrollview水平和垂直滾動
- 23. 100%寬度+水平和垂直滾動
- 24. 水平和垂直滾動UITableView
- 25. UItextview水平和垂直滾動
- 26. IOS中的垂直和水平滾動
- 27. 垂直和水平滾動表
- 28. 垂直滾動和水平頁面表
- 29. jquery fullpage垂直和水平滾動
- 30. 在UITableview中水平和垂直滾動
在很多情況下,任何需要大量空間的東西都不應該使用ScrollView/HorizontalScrollView。只有當內容在內存消耗方面仍然相當適中時,這些纔有用。在頻譜的另一端,考慮谷歌地圖 - 這不是使用ScrollView或HorizontalScrollView實現的,因爲我們無法一次在RAM中保存整個地球的地圖。想一想你想要滾動的內容,因爲很可能你需要做一些比使用'ScrollView'和親族來處理移動設備更復雜的東西。 – CommonsWare 2011-04-24 15:44:08
我的解決方案是計算哪個關卡(這是一款遊戲)的物體在屏幕上,並且只繪製這些物體。另一種解決方案是使用父寬度/高度的框架視圖,並在事件發生時移動關卡的對象。後者似乎需要更多的處理,但可能更少的RAM。你有推薦嗎? – 2011-04-24 15:50:55
「我的解決方案是計算哪個關卡(這是一款遊戲)的物體在屏幕上,並且只繪製這些關卡。」 - 我不是遊戲開發者,但是這聽起來像你不需要'ScrollView'和親戚,然後,你自己正在處理它。只需注意滑動事件並重新繪製您的關卡。 – CommonsWare 2011-04-24 16:19:42