gpt4 book ai didi

android - RecyclerView 或 CollapsingToolbarLayout 中的 WebView 如何滚动?

转载 作者:太空狗 更新时间:2023-10-29 14:36:12 25 4
gpt4 key购买 nike

我想在RecyclerView(试过也失败)或CollapsingToolbarLayout中使用WebView,但是html的组件无法滚动,它是CollapsingToolbarLayout中的webview,timezone popupWindow无法滚动。

enter image description here

Activity 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&lt;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>

之前RecyclerView使用了itemview,所以样式可能看起来很糟糕。我认为 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的timezone可以滚动呢?

最佳答案

使用 NestedScrollView 作为父级并在设置适配器后放置此行 ViewCompat.setNestedScrollingEnabled(recyclerView, false);

关于android - RecyclerView 或 CollapsingToolbarLayout 中的 WebView 如何滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55140630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com