【问题标题】:How I can use horizontal scroll view in fragments?如何在片段中使用水平滚动视图?
【发布时间】:2019-04-25 04:58:17
【问题描述】:

我正在处理片段我需要在片段中使用水平滚动视图。我知道如何在活动中添加它,但我不知道如何在片段中添加水平滚动视图?

【问题讨论】:

标签: android android-fragments


【解决方案1】:

我认为在活动或片段上创建水平滚动视图之间没有区别。请记住,您应该在其中添加一个布局。在一些罕见的情况下,我在活动上使用滚动视图时遇到错误并且无法移动片段滚动视图,因此,我的做法是仅在片段上使用滚动视图。

一个例子:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f1f1f1"
    tools:context=".Fragments.Example">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.CardView
                    android:layout_width="900dp"
                    android:layout_height="300dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Example"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                    </android.support.constraint.ConstraintLayout>

                </android.support.v7.widget.CardView>

            </android.support.constraint.ConstraintLayout>

        </HorizontalScrollView>

    </android.support.constraint.ConstraintLayout>

</ScrollView>

成功了。 (已测试)

【讨论】:

    猜你喜欢
    • 2015-08-09
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    • 2018-05-08
    • 2016-01-29
    相关资源
    最近更新 更多