【问题标题】:Android Layout problem with flexible content in a scrolling fragment滚动片段中具有灵活内容的Android布局问题
【发布时间】:2020-12-04 07:02:23
【问题描述】:

我在为以下情况创建 Android 布局时遇到问题: 它是一个片段,顶部有一个 webview,下面有一些其他布局组件。 webview 本身不应该是可滚动的。孔片段应该是可滚动的。这是一个更好的可视化图像。

webview 和 recyclerview 高度灵活,具体取决于内容。 webview 和 recylerview 应该始终显示所有内容而不滚动。孔片段应该是可缩放的。

我尝试了几种滚动视图、嵌套滚动视图和约束布局的组合。但大多数时候我的 webview 没有显示。

我的问题是:这个布局组件应该如何嵌套以及组件高度的正确选项是什么(match_parent,....)?

这是我最近尝试的一个示例。未显示 web 视图。

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:fillViewport="true"
    android:requiresFadingEdge="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            app:layout_constraintBottom_toTopOf="@+id/txtSimilarTopics"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <View
            android:id="@+id/scrollToTopHelper"
            android:layout_width="100dp"
            android:layout_height="150dp"
            app:layout_constraintBottom_toBottomOf="@+id/webView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <TextView
            android:id="@+id/txtSim"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="16dp"               
            android:textColor="@color/colorBlack"
            android:textSize="20sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/webView"
            tools:text="Ähnliche Themen" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/txt"
            tools:itemCount="3"
             />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

【问题讨论】:

  • 我会尝试将所有内容放在ScrollView 中,并将wrap_content 作为WebViewRecyclerView 的高度。后者应确保显示所有内容(尽管这超出了RecyclerView 的目的,不是吗?)。 ScrollView 中包含的布局可以是带有vertical 方向的LinearLayout,或者是ConstraintLayout 或...。没有测试,所以不确定它是否会工作。
  • 听起来像是我最近的尝试。已附上代码。
  • 嗯,我不太清楚。回想起来,wrap_content 对于RecyclerView 可能不是一个好主意。无论如何,祝你好运解决这个问题。

标签: android android-layout android-fragments android-constraintlayout android-scrollview


【解决方案1】:

所以这不是布局问题。我的问题是由网页上的 JavaScript 错误引起的。这就是页面没有显示的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2013-01-10
    • 2016-03-31
    • 2012-11-16
    相关资源
    最近更新 更多