我在CoordinatorLayout
主布局中有一个布局,其中又包含两个布局。
两种布局如下:
此布局( layout_bottom_sheet.xml )充当BottomSheet
。
我想使RecyclerView
内的NestedScrollView
可滚动,但是当我尝试滚动时,BottomSheet
每次都会得到焦点。
我知道RecyclerView
只要有焦点就可以滚动。
任何帮助将不胜感激。谢谢
我在这里列出了所有布局,以便更好地理解问题。
这是主要布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true"
android:focusable="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/white"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="?android:attr/selectableItemBackground"
android:padding="16dp"
android:src="@drawable/ic_back_toolbar" />
<com.creatrixe.commo.utils.customviews.CustomTextView
android:id="@+id/tv_dest_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Add Activities in Dallas TX"
android:textColor="@color/post"
android:textSize="@dimen/_14ssp"
app:customFont="Avenir-Medium.ttf" />
<ImageView
android:id="@+id/iv_add_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="?android:attr/selectableItemBackground"
android:padding="16dp"
android:src="@drawable/ic_plus_activity" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/layout_map_view" />
<include layout="@layout/layout_bottom_sheet" />
</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.CoordinatorLayout>
主布局包含一个CoordinatorLayout
,其中又包含两个布局。
1。 layout_map_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2。 layout_bottom_sheet.xml
<LinearLayout
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/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
app:behavior_peekHeight="@dimen/_120sdp"
app:layout_behavior=
"android.support.design.widget.BottomSheetBehavior">
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="@dimen/_12sdp"
android:background="@drawable/gradient_days" />
<ImageView
android:id="@+id/iv_bs_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/_8sdp"
android:src="@drawable/ic_bs_collapsed" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingStart="@dimen/_24sdp"
android:paddingEnd="@dimen/_24sdp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:listitem="@layout/item_trip_days" />
<com.creatrixe.commo.utils.customviews.CustomTextView
android:id="@+id/tv_selected_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Tuesday, 18 Apr 2019"
android:textColor="#3391D8"
android:textSize="@dimen/_14ssp"
app:customFont="Avenir-Medium.ttf" />
<View
android:id="@+id/view_bottom"
android:layout_width="match_parent"
android:layout_height="@dimen/_12sdp"
android:layout_marginTop="@dimen/_8sdp"
android:background="@drawable/gradient_days"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_activity_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/_8sdp" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
layout_bottom_sheet在RecyclerView
内包含NestedScrollView
RecyclerView
项目:
item_activities_in_date.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/view_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:orientation="vertical">
<com.creatrixe.commo.utils.customviews.CustomTextView
android:id="@+id/tv_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:paddingStart="@dimen/_4sdp"
android:paddingEnd="@dimen/_4sdp"
android:singleLine="true"
android:text="Friday, 22nd December 2018"
android:textColor="#3391D8"
android:textSize="@dimen/_16ssp"
app:customFont="Avenir-Medium.ttf"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_activity_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_date"
tools:listitem="@layout/item_activity_card" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
item_activities_in_date 包含另外一个RecyclerView
。
RecyclerView
项目:
item_activity_card.xml
<?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"
android:id="@+id/view_root"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginTop="@dimen/_2sdp"
android:layout_marginEnd="@dimen/_8sdp"
app:cardCornerRadius="@dimen/_8sdp"
app:cardElevation="@dimen/_4sdp"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cl_activity_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/_4sdp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/iv_activity"
android:layout_width="@dimen/_40sdp"
android:layout_height="@dimen/_40sdp"
android:src="@color/light_grey"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/_6sdp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@id/iv_activity"
app:layout_constraintEnd_toStartOf="@id/iv_delete_activity"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/iv_activity"
app:layout_constraintTop_toTopOf="@id/iv_activity">
<com.creatrixe.commo.utils.customviews.CustomTextView
android:id="@+id/tv_activity_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_6sdp"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:text="Capital Factory - 701 Brazos Street"
android:textColor="@color/coomo_community"
android:textSize="@dimen/_12ssp"
app:customFont="Avenir-Medium.ttf" />
<RatingBar
android:id="@+id/rating"
style="@style/Base.Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_6sdp"
android:max="5"
android:rating="5"
app:layout_constraintStart_toEndOf="@id/iv_activity"
app:layout_constraintStart_toStartOf="@id/tv_activity_details"
app:layout_constraintTop_toBottomOf="@+id/tv_activity_details" />
</LinearLayout>
<ImageView
android:id="@+id/iv_delete_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:id="@+id/ll_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_12sdp"
android:gravity="center|start"
app:layout_constraintStart_toStartOf="@+id/card_view"
app:layout_constraintTop_toBottomOf="@+id/card_view">
<ImageView
android:id="@+id/iv_med"
android:layout_width="@dimen/_8sdp"
android:layout_height="@dimen/_26sdp"
android:src="@drawable/ic_medium"
app:layout_constraintStart_toStartOf="@+id/card_view"
app:layout_constraintTop_toBottomOf="@+id/card_view" />
<ImageView
android:id="@+id/iv_man"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_4sdp"
android:src="@drawable/ic_man"
app:layout_constraintBottom_toBottomOf="@id/iv_med"
app:layout_constraintStart_toEndOf="@id/iv_med"
app:layout_constraintTop_toBottomOf="@+id/card_view"
app:layout_constraintTop_toTopOf="@id/iv_med" />
<com.creatrixe.commo.utils.customviews.CustomTextView
android:id="@+id/tv_walking_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_8sdp"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:text="2h 13m"
android:textColor="@color/coomo_community"
android:textSize="@dimen/_12ssp"
app:customFont="Avenir-Medium.ttf"
app:layout_constraintBottom_toBottomOf="@id/iv_med"
app:layout_constraintStart_toEndOf="@id/iv_man"
app:layout_constraintTop_toBottomOf="@+id/card_view"
app:layout_constraintTop_toTopOf="@id/iv_med" />
<ImageView
android:id="@+id/iv_car"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_4sdp"
android:src="@drawable/ic_car_distance"
app:layout_constraintBottom_toBottomOf="@id/tv_walking_dist"
app:layout_constraintStart_toEndOf="@id/tv_walking_dist"
app:layout_constraintTop_toBottomOf="@+id/card_view"
app:layout_constraintTop_toTopOf="@id/tv_walking_dist" />
<com.creatrixe.commo.utils.customviews.CustomTextView
android:id="@+id/tv_car_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_8sdp"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:text="33m"
android:textColor="@color/coomo_community"
android:textSize="@dimen/_12ssp"
app:customFont="Avenir-Medium.ttf"
app:layout_constraintBottom_toBottomOf="@id/iv_car"
app:layout_constraintStart_toEndOf="@id/iv_car"
app:layout_constraintTop_toBottomOf="@+id/card_view"
app:layout_constraintTop_toTopOf="@id/iv_car" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
尝试在RecyclerView中设置focusableOnTouchMode = true