我在实施工具栏时遇到了一些麻烦,但它从不停留在一个地方。这是由于布局中有recyclerView
的一些自动滚动事件,我很奇怪,因为没有scrollView
。
如何解决此问题,以便滚动时工具栏处于固定位置?
这是我的代码,所以你可以告诉我我需要做些什么来解决它。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
tools:context="com.example.user.app.Utils.ViewProfileFragment">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorS50Alpha"
android:elevation="2dp"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ivProfileBackphoto"
android:layout_width="0dp"
android:layout_height="320dp"
android:background="@drawable/background_signinandregister"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@color/colorProfileBack" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="150dp"
android:background="@drawable/shadow_profile_01"
app:layout_constraintBottom_toBottomOf="@+id/ivProfileBackphoto"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
android:id="@+id/relativeLayout5">
</RelativeLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/ivProfilephoto"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="@+id/ivProfileBackphoto"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.361" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:text="Foster The People"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColor="@android:color/white"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="@+id/ivProfileBackphoto"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ivProfilephoto"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.497" />
<TextView
android:id="@+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="1dp"
android:text="I like bacon and cheese sandwiches"
android:textAlignment="center"
android:textColor="@color/colorGrey"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/ivProfileBackphoto"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvName"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/ivAddFriend"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@+id/relativeLayout5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/ivProfilephoto"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.418"
app:srcCompat="@drawable/addfriend02" />
<ImageView
android:id="@+id/ivRemoveFriend"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@+id/relativeLayout5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/ivProfilephoto"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.418"
app:srcCompat="@drawable/removefriend02" />
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tbProfiletabs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/toolbar01"
android:layout_marginTop="264dp"
android:background="@color/colorS50Alpha"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relativeLayout5"
app:layout_constraintVertical_bias="0.0"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/colorSearch">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Center" />
</android.support.design.widget.TabLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/lvProfilePosts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tbProfiletabs"
android:visibility="visible" />
<android.support.v4.view.ViewPager
android:id="@+id/profileTabsViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tbProfiletabs">
</android.support.v4.view.ViewPager>
</RelativeLayout>
答案 0 :(得分:0)
尝试像这样更改回收代码
<android.support.v7.widget.RecyclerView
android:id="@+id/lvProfilePosts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar01"
android:visibility="visible" />
我认为工具栏停留在那里,但回收视图在工具栏上滚动。
答案 1 :(得分:0)
android:focusable="true"
android:focusableInTouchMode="true"
将以上行添加到您的根布局,大小写中的相对布局
试试这个
<RelativeLayout 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="@color/actBackgroundColor"
tools:context="com.playglam.activities.ViewAddressActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<com.playglam.others.custom_view.MyTextViewThin
android:id="@+id/txtTitle"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font_size_20"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvAddress"
android:layout_marginTop="@dimen/dim_5"
android:layout_below="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabNewAddress"
app:srcCompat="@drawable/ic_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/dim_10"
android:layout_marginRight="@dimen/dim_10"
app:elevation="@dimen/dim_5"
app:fabSize="normal"
app:rippleColor="@color/colorAccent" />
答案 2 :(得分:0)
我通过添加NestedScrollView
来修复它。