如何将底图设置为底部导航视图的顶部

时间:2017-12-01 10:14:41

标签: android bottom-sheet android-nestedscrollview

我正在尝试显示底部表格以及BottomNavigationview。 But overlapping. Check Here

我将如何给底部页面提供底部边距。

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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/bottomSheet"
    android:background="@android:color/white"
    android:paddingTop="@dimen/activity_horizontal_margin"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/bottomSheetRecyclerview"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

</android.support.v4.widget.NestedScrollView>

实施代码:

 override fun openBottomDialogView() {

        val bottomSheetView= findViewById<NestedScrollView>(R.id.bottomSheet) as NestedScrollView
        Log.e("Bottom sheet view ",bottomSheetView.toString())


         dashboardBottomSheetBehaviour = BottomSheetBehavior.from(bottomSheetView)
            dashboardBottomSheetBehaviour.isHideable=true

        if(dashboardBottomSheetBehaviour.getState() != BottomSheetBehavior.STATE_EXPANDED) {

            bottomSheetRecyclerview.layoutManager= LinearLayoutManager(this@DashboardActivity) as RecyclerView.LayoutManager?
            bottomSheetRecyclerview.adapter= BottomSheetDialogAdaptor(this@DashboardActivity, getBottomSheetitem())
            dashboardBottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
        else {
            closeBottomView()
        }
    }

我尝试设置nestedscrollview的固定高度,然后给出边距但是也没有用。

关于我面临的新问题

fun closedBottomView(){
     Log.e("CLose ","Old bottom sheet")
        dashboardBottomSheetBehaviour.state=BottomSheetBehavior.STATE_HIDDEN
        Log.e("Final state ",dashboardBottomSheetBehaviour.state.toString())

}

这里的最终日志表明底层状态处于STATE_SETTLING状态。但回调称它处于HIDDEN状态。

2 个答案:

答案 0 :(得分:1)

尝试使用:layout_anchorBottomNavigationView将其锚定在BottomSheetView的顶部/底部

 app:layout_anchor="@+id/bottomSheet" --> BottomSheet view ID
 app:layout_anchorGravity="bottom|end"

有关详细信息,请查看This Link

答案 1 :(得分:0)

我要解决的方法是用视图包裹原始的底部表单,并用72dp(大约是底部导航栏的大小)设置最顶部视图的大小。 示例:

<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="184dp"
app:behavior_hideable="true"
android:backgroundTint="@android:color/transparent"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
tools:showIn="@layout/activity_main">


<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="112dp"
    android:background="@drawable/bg_rounded_transparent">

    <ImageView
        android:id="@+id/imageViewThumbnailMap"
        android:layout_width="156dp"
        android:layout_height="match_parent"
        android:background="@drawable/bg_rounded_transparent"
        android:scaleType="fitXY"
        android:src="@drawable/ic_logo"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:id="@+id/textViewThumbnailDistance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Caption"
        app:layout_constraintBottom_toTopOf="@+id/textViewThumbnailName"
        app:layout_constraintStart_toEndOf="@+id/imageViewThumbnailMap"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="5km" />

    <TextView
        android:id="@+id/textViewThumbnailName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Headline"
        app:layout_constraintBottom_toTopOf="@+id/textViewThumbnailDateTime"
        app:layout_constraintStart_toEndOf="@+id/imageViewThumbnailMap"
        app:layout_constraintTop_toBottomOf="@+id/textViewThumbnailDistance"
        tools:text="Karaoke golos" />

    <TextView
        android:id="@+id/textViewThumbnailDateTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/imageViewThumbnailMap"
        app:layout_constraintTop_toBottomOf="@+id/textViewThumbnailName"
        tools:text="19:30-23:50" />
</android.support.constraint.ConstraintLayout>

enter image description here

相关问题