material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[Component name] Bug: empty space being created for something I've set to fill the space inside BottomSheet

Open AndroidDeveloperLB opened this issue 1 year ago • 0 comments

Description: Full description of issue here I just wanted to have some scrollable content in BottomSheetDialogFragment.

Expected behavior: Screenshots and/or description of expected behavior Fill the space of the bottom sheet, having the TextView at the top of the content.

What happens instead is that it got empty space above the TextView.

image

Source code: The code snippet which is causing this issue

<androidx.coordinatorlayout.widget.CoordinatorLayout
    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/bottomSheetRoot"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="#330000ff">

    <FrameLayout
        android:id="@+id/standard_bottom_sheet" android:layout_width="match_parent"
        android:layout_height="match_parent" android:layout_gravity="center_horizontal"
        android:background="#3300ff00"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

        <TextView
            android:layout_width="200dp" android:layout_height="200dp"
            android:layout_gravity="center_horizontal" android:background="#33ff0000"
            android:gravity="center" android:text="Hello bottom sheet" />

    </FrameLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
class ModalBottomSheet : BottomSheetDialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
            inflater.inflate(R.layout.modal_bottom_sheet_content, container, false)

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog: BottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
        dialog.behavior.saveFlags = BottomSheetBehavior.SAVE_ALL
        return dialog
    }

    companion object {
        const val TAG = "ModalBottomSheet"
    }
}
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        findViewById<View>(R.id.button).setOnClickListener {
            val modalBottomSheet = ModalBottomSheet()
            modalBottomSheet.show(supportFragmentManager, ModalBottomSheet.TAG)
        }
    }
}

Android API version: Android API version here 35

Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07) 1.13.0-alpha07

Device: Device on which the bug was encountered here Pixel 6.

My Application.zip

AndroidDeveloperLB avatar Oct 18 '24 20:10 AndroidDeveloperLB