我想在RecyclerView(尝试并失败)或CollapsingToolbarLayout中使用WebView,但是html的组件无法滚动,这是CollapsingToolbarLayout中的Webview,时区popupWindow无法滚动。
活动xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data></data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:id="@+id/appbar"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
android:id="@+id/topview"
layout="@layout/itemview_crypto_kline"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
itemview_crypto_kline.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="ticker"
type="androidx.lifecycle.MutableLiveData<data.bean.Ticker>" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bottomColor"
android:orientation="vertical">
<TextView
android:id="@+id/tv_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginTop="@dimen/small_margin"
android:text='@{ticker.close+""}'
android:textColor="@color/decreasingColor"
android:textSize="@dimen/ic_text_size" />
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginBottom="@dimen/small_margin"
android:text='@{ticker.time}'
android:textColor="@color/tip_color"
android:textSize="@dimen/very_small_text_size" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginBottom="@dimen/small_margin">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/open"
android:textColor="@color/tip_color"
android:textSize="@dimen/very_small_text_size" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/small_margin"
android:layout_weight="2"
android:text='@{ticker.open+""}'
android:textColor="@color/textColor"
android:textSize="@dimen/very_small_text_size" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/border_margin"
android:layout_weight="1"
android:text="@string/vol"
android:textColor="@color/tip_color"
android:textSize="@dimen/very_small_text_size" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/small_margin"
android:layout_weight="2"
android:text='@{ticker.vol+""}'
android:textColor="@color/textColor"
android:textSize="@dimen/very_small_text_size" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="4" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginBottom="@dimen/small_margin">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/high"
android:textColor="@color/tip_color"
android:textSize="@dimen/very_small_text_size" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/small_margin"
android:layout_weight="2"
android:text='@{ticker.high+""}'
android:textColor="@color/textColor"
android:textSize="@dimen/very_small_text_size" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/border_margin"
android:layout_weight="1"
android:text="@string/low"
android:textColor="@color/tip_color"
android:textSize="@dimen/very_small_text_size" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/small_margin"
android:layout_weight="2"
android:text='@{ticker.low+""}'
android:textColor="@color/textColor"
android:textSize="@dimen/very_small_text_size" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="4" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="@dimen/small_margin"
android:background="@color/colorPrimary">
<WebView
android:id="@+id/webview"
android:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="300dp" />
<View
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@color/colorPrimary" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small_margin"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="10dp"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<ImageView
android:id="@+id/iv_refresh"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginBottom="@dimen/small_margin"
android:src="@drawable/ic_refresh" />
<ImageView
android:id="@+id/iv_translate"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginBottom="@dimen/small_margin"
android:src="@drawable/ic_translate" />
<ImageView
android:id="@+id/iv_fullscreen"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginEnd="@dimen/border_margin"
android:layout_marginBottom="@dimen/small_margin"
android:src="@drawable/ic_fullscreen" />
</LinearLayout>
</LinearLayout>
</layout>
itemview以前被RecyclerView使用,所以样式看起来很糟糕。 我认为RecyclerView或CoordinatorLayout花费了该事件,但是当我尝试下面的代码时,它也无法滚动。
AppBarLayout.LayoutParams layoutParams = (AppBarLayout.LayoutParams) binding.collapsing.getLayoutParams();
layoutParams.setScrollFlags(0);
binding.collapsing.setLayoutParams(layoutParams);
webview的html在下面:
<body style="margin:0;padding:0;background-color:#2c2d3b">
<div class="tradingview-widget-container">
<div id="tradingview_49c3f"></div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget({"autosize": true,"symbol": "COINBASE:BTCUSD","interval": "1","timezone": "America/New_York","theme": "Dark","style": "3","locale": "en","toolbar_bg": "#f1f3f6","enable_publishing": false,"hide_top_toolbar": true,"hide_legend": true,"withdateranges": true,"save_image": false,"container_id": "tradingview_49c3f"});
</script>
</div>
</body>
那么如何使webview的时区可以滚动?
答案 0 :(得分:0)
您可以尝试webview.setVerticalScrollBarEnabled(true);
webview.setHorizontalScrollBarEnabled(true);
可能有帮助
答案 1 :(得分:0)
使用NestedScrollView作为父项,并在设置适配器ViewCompat.setNestedScrollingEnabled(recyclerView, false);