【问题标题】:BottomSheetDialogFragment has bottom part of it cut off when createdBottomSheetDialogFragment 在创建时将其底部截断
【发布时间】:2020-12-30 19:36:27
【问题描述】:

我使用的是 BottomSheetDialogFragment,但是当我展示它时,它的一部分在底部被切断了。 为什么它没有完全充气,我该如何解决这个问题?

这是完整的布局和用法:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    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="wrap_content">

    <TextView
        android:id="@+id/fragplaces_app_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="12dp"
        android:paddingTop="16dp"
        android:paddingEnd="12dp"
        android:paddingBottom="16dp"
        android:text="test"
        android:textColor="@color/colorWhite"
        android:textStyle="bold"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/background_top_round_corners_blue"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/fragnearme_recycler"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:background="@color/backgroundColor"
        android:paddingBottom="8dp"
        android:scrollbars="vertical"
        app:layout_constraintTop_toBottomOf="@+id/fragplaces_app_name"
        app:layout_constraintBottom_toTopOf="@+id/send_msg_layout"/>

    <RelativeLayout
        android:id="@+id/send_msg_layout"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="@color/backgroundColor"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:paddingBottom="8dp">

        <ImageView
            android:id="@+id/btn_emoji"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            app:srcCompat="@drawable/ic_grey_smiley_24dp"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"/>

        <EditText
            android:id="@+id/challengeroom_et_sendmessage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toEndOf="@id/btn_emoji"
            android:background="@drawable/background_chat_send_message"
            android:gravity="center_vertical"
            android:hint="Type a message"
            android:inputType="text"
            android:maxLines="1"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:textColorHint="@color/defaultTextColor"
            android:textSize="14sp" />

    </RelativeLayout>


    
</androidx.constraintlayout.widget.ConstraintLayout>

用法:

BottomSheetDialogFragment chatFragment = new ChatFragment();
chatFragment.show(getSupportFragmentManager(), Constants.FRAGMENT_CHAT);

我尝试将父约束布局高度更改为match_parent,并尝试将其设置为定义的高度,例如 500dp,但它仍然不起作用。

【问题讨论】:

    标签: android android-bottomsheetdialog


    【解决方案1】:

    在我的 BottomSheetDialog 的样式中添加 &lt;item name="behavior_peekHeight"&gt;500dp&lt;/item&gt; 解决了这个问题。

    <style name="BottomSheetRoundedCorners" parent="Widget.Design.BottomSheet.Modal">
            <item name="android:background">@drawable/background_top_round_corners</item>
            <item name="behavior_peekHeight">500dp</item>
        </style>
    
        <style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
            <item name="bottomSheetStyle">@style/BottomSheetRoundedCorners</item>
            <item name="behavior_draggable">false</item>
    
        </style>
    

    并在我的主要应用主题中使用它:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
    </style>
    

    感谢这个答案:

    https://stackoverflow.com/a/35720641/11110509

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      相关资源
      最近更新 更多