BottomSheetDialogFragment setting look beyond and other behaviors

I want the bottom screen to drop in and then rise in full screen when it slides up. I'm currently showing when I press "Button 1" because I cannot get peek to work.

enter image description here

I can, however, move it up so that it occupies the entire screen. Ideally, this will be done automatically.

enter image description here

When I move it back, it completely lowers.

enter image description here

I need the following behavior:

  • The bottom sheet should drop in 300dpor whatever, at any time.

  • Slipping on the bottom sheet should lead to the fact that it displays a full screen, as in the second figure.

  • A shift down the bottom sheet should return to its peeking height.

, Bottom Sheet, BottomSheetBehavior , XML.

activity_main.xml

<android.support.design.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/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <Button
            android:id="@+id/button_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 1"
            android:padding="16dp"
            android:layout_margin="8dp"
            android:textColor="@android:color/white"
            android:background="@android:color/holo_green_dark"/>

            // ... 
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

fragment_bottom_sheet.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="true"
    android:background="@android:color/holo_orange_light"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Some text..."
        android:padding="16dp"
        android:textSize="16sp"/>

</RelativeLayout>

MainActivity.java

package com.example.qqq.bottomsheets;

import android.os.Bundle;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private BottomSheetBehavior mBottomSheetBehavior;
    private TestBottomSheetDialogFragment mTestBottomSheetDialogFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = (Button) findViewById( R.id.button_1 );
        Button button2 = (Button) findViewById( R.id.button_2 );
        Button button3 = (Button) findViewById( R.id.button_3 );

        mTestBottomSheetDialogFragment = new TestBottomSheetDialogFragment();

        button1.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch(v.getId()) {
            case R.id.button_1: {
                mTestBottomSheetDialogFragment.show(getSupportFragmentManager(), mTestBottomSheetDialogFragment.getTag());
                break;
            }
        }
    }
}

TestBottomSheetDialogFragment.java

package com.example.qqq.bottomsheets;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TestBottomSheetDialogFragment extends BottomSheetDialogFragment {


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return super.onCreateDialog(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
        return view;
    }

}
+4

Source: https://habr.com/ru/post/1668053/


All Articles