滚动查看个人资料活动

时间:2019-04-17 13:56:45

标签: java android android-fragments

您好,我有一个个人资料活动,登录时会将用户带到该活动中,然后将其分段到不同的页面。我希望这些片段具有滚动功能,但是在使用滚动视图时却什么也没做。为了使片段滚动,我有什么选择。

我尝试将滚动视图放入个人资料活动和片段本身中。

<?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 
    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="@android:color/white"
    tools:context=".ProfileActivity">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.39"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.436">

        <Button
            android:id="@+id/buttonLogout"
            android:layout_width="60dp"
            android:layout_height="25dp"
            android:layout_marginStart="347dp"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="0dp"
            android:background="@color/design_default_color_primary"
            android:textColor="@android:color/background_light"
            android:text="@string/logout" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/main_nav"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            app:menu="@menu/navigation">

        </android.support.design.widget.BottomNavigationView>

        <ImageView
            android:id="@+id/uobLogo"
            android:layout_width="70dp"
            android:layout_height="60dp"
            android:layout_marginStart="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="0dp"
            android:src="@drawable/uoblogo" />

        <FrameLayout
            android:id="@+id/main_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/main_nav"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true">
        </FrameLayout>

    </RelativeLayout>
</android.support.constraint.ConstraintLayout>

//以上代码来自个人资料活动xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SymptomsFragment">

    <TextView
        android:id="@+id/TitleSymptoms"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:textSize="40sp"
        android:textStyle="bold"
        android:textColor="@color/design_default_color_primary"
        android:text="@string/TitleSymptoms"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/paragraph2"
        android:layout_width="match_parent"
        android:layout_height="435dp"
        android:layout_gravity="center_vertical"
        android:textSize="14sp"
        android:textStyle="italic"
        android:textColor="@color/colorAccent"
        android:text="@string/paragraph2" />

</FrameLayout>

//以上代码来自症状片段

1 个答案:

答案 0 :(得分:0)

尝试执行以下操作:

<?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"
tools:context=".ProfileActivity">

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

    <!--Here you put your views-->


</android.support.constraint.ConstraintLayout>

</ScrollView>

因此,我们的想法是您的父布局(在这种情况下为ScrollView)包含您需要滚动的所有视图,在这种情况下,您的RelativeLayout包含其所包含的所有视图