嗨,我有一个配置文件活动,用户在登录时被带到其中,然后它有不同页面的片段。我希望这些片段具有滚动功能,但在使用滚动视图时,这什么也没做。我有什么选择才能让片段滚动。
我尝试将滚动视图放入配置文件活动和片段本身中。
<?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>
上面的代码来自症状片段
尝试做这样的事情:
<?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包含它包含的所有视图