【问题标题】:How to set ConstraintLayout End of Top Bottom Sheet如何设置 ConstraintLayout End of Top Bottom Sheet
【发布时间】:2021-10-31 18:16:18
【问题描述】:

如何设置botton group layout_constraintEnd_toTopOf Bottom Sheet 当向上或向下滑动按钮组时,请跟随

我尝试了几种方法,但仍然无法像下面的红色箭头一样。

下面是主要的xml 我在片段和线性布局之间使用了 CoordinatorLayout

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.mapbox.mapboxsdk.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            mapbox:mapbox_cameraTargetLat="40.73581"
            mapbox:mapbox_cameraTargetLng="-73.99155"
            mapbox:mapbox_cameraZoom="11"/>

    </FrameLayout>


    <include layout="@layout/bottom_sheet"/>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/layout_options_inside"
        android:layout_width="match_parent"
        android:layout_height="700dp"
        android:orientation="vertical">


        <com.google.android.material.button.MaterialButtonToggleGroup
            android:id="@+id/toggleButtonGroup2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/transparent_white"
            android:orientation="vertical"
            app:singleSelection="true"
            android:layout_marginEnd="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            >


            <Button
                android:id="@+id/btnLeft"
                style="@style/ToggleButtonWithIconOnly"
                app:icon="@drawable/ic_outline_near_me_24"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:layout_editor_absoluteX="168dp"
                tools:layout_editor_absoluteY="153dp" />

            <Button
                android:id="@+id/btnCenter"
                style="@style/ToggleButtonWithIconOnly"
                app:icon="@drawable/ic_baseline_search_24"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:layout_editor_absoluteX="173dp"
                tools:layout_editor_absoluteY="251dp" />

        </com.google.android.material.button.MaterialButtonToggleGroup>



    </androidx.constraintlayout.widget.ConstraintLayout>




</androidx.coordinatorlayout.widget.CoordinatorLayout>

下面是我的包含底部工作表 xml 布局 我尝试在 LinearLayout 中添加 ConstraintLayout 布局,但我不能使用底页

<?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"
    android:orientation="vertical"
    android:id="@+id/bottomSheet"
    app:layout_behavior="@string/bottom_sheet_behavior"
    app:behavior_peekHeight="?actionBarSize"
    android:layout_width="match_parent"
    android:layout_height="300dp">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="@drawable/rounded_bottomsheet"
        android:paddingEnd="8dp"
        android:paddingStart="8dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_baseline_remove_24"
                android:layout_gravity="center|top"
                />
        </FrameLayout>

    </RelativeLayout>

</LinearLayout>

感谢大家的回答

【问题讨论】:

    标签: android android-layout android-fragments


    【解决方案1】:

    尝试将切换组锚定到底部工作表

        app:layout_anchor="@id/bottom_sheet"
        app:layout_anchorGravity="end"
    

    【讨论】:

    • 不工作它堆叠在 CoordinatorLayout
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 2021-01-14
    • 2010-09-22
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    相关资源
    最近更新 更多