如果你希望所有的意見,得到滾動單滾輪裏面,有一個非常有用的庫 - commonsguy/cwac-merge
有你需要Ø滿足使用單個條件代碼如下。請記住,針對您的問題的這種方法可能會有所不同,但最終結果正是您需要的。
條件:
- 這個庫只能與ListView的使用。
這就是所有,讓我們開始。
讓你的活動佈局這樣的:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</RelativeLayout>
創建一個新的佈局XML。讓它被命名爲viewWebView.xml
並粘貼 此代碼:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:background="#767676">
</WebView>
</RelativeLayout>
創建一個新的佈局XML。讓它被命名爲viewTextView.xml
並粘貼 此代碼:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello There"
android:textColor="#FFFFFF">
</TextView>
</RelativeLayout>
所以,現在我們有一個Java文件的工作。打開你的* Activity.java文件 和庫的用法如下。
ListView list = (ListView) findViewById(R.id.list);
MergeAdapter mg = new MergeAdapter();
/**
* Prgram your webview
*/
View web = getLayoutInflater().inflate(R.layout.viewWebView, null);
WebView web = (WebView) web.findViewById(R.id.webView);
//TODO: Code your webview!!
mg.addView(web);
mg.addView(getLayoutInflater().inflate(R.layout.viewTextView, null));
list.setAdapter(mg);
觀光Rememeber:MergeAdpater
下
- 意見將在您添加視圖的方式加入。換句話說,您的順序是
mg.addView(View)
將是ListView中項目出現的順序。
乾杯!如果您在執行任何操作時遇到任何問題,或者將庫添加到Gradle中,請讓我知道!
祝你好運!
要幫助你的人,這個問題需要清除。你的問題不清楚。那麼,爲什麼你想要滾動根視圖?或者你想從滾動rootView中獲得什麼?因爲視圖無論如何都是可滾動的。 – Want2bExpert
將Scrollable視圖放入另一個Scrollable視圖是一種**糟糕的做法。 –
因爲我有其他意見,並且webview不夠高 – LichFaker