[英]ScrollView doesn't work
我的布局有一些復雜的布局,它們很大。 這就是為什么我需要ScrollView
的原因。 但是,無論我嘗試什么,都行不通。
這是我的布局文件:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:id="@+id/Linear1"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/tileColor1"
android:layout_weight="1"
android:id="@+id/tileLayout1"
android:onClick="openFirst"
>
我只發布了一部分,但所有的結束標記都可以,並且在我的RelativeLayout
有2個textViews
和一個圖像。 還有9個具有相同結構的RelativeLayout
。
如何解決該問題,為什么不起作用? 它甚至不顯示滾動條。
編輯
編輯2
在developer.android上說: You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
我的根本不處理滾動。 我想是因為我在代碼中編輯LayoutParams。 我該如何解決?
1.嘗試刪除android:layout_weight="1"
和android:orientation="vertical"
。
2.確保ScrollView
只有一個ViewGroup
(即,他們所說的一個孩子)。 我認為您已經完成了此操作,但是由於您沒有提供完整的布局,因此無法確認。
ScrollView僅接受一個子視圖。 因此,將其中的所有內容包裝在LinearLayout中,並將wrap_content設置為height即可。
我遇到了同樣的問題,我不知道我的解決方案是否有幫助(主要是因為響應太晚了),但是我的ScrollView
不能正常工作,因為它設置了恰好適合屏幕的布局,因此沒有必要創建滾動。 增加布局后(我將所有項目都放置在android:layout_height = WRAP_CONTENT
)就可以使用了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.