Text height for Android Bottomsheet TextView not adjusted when first expanded

TL DR: TextViewin Bottomsheet, not displaying multiline text the first time it is Bottomsheetexpanded, but adjusted after it is minimized.

So, I use the Bottomsheet from the library design-23.2.1.

My layout file is as follows:

<android.support.design.widget.CoordinatorLayout>

    ......

    <LinearLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>
</android.support.design.widget.CoordinatorLayout>

The content Bottomsheetis basically a list:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView 
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:singleLine="false" />
    ...
</LinearLayout>

The problem occurs when the parameter is Bottomsheetset STATE_EXPANDED to the first time , it TextViewis a separate line, and the text is wrapped, and there is no ellipse in the end line.

Then, after it is set to STATE_COLLAPSED, the height is TextViewcorrect and multi-line.

, , ​​ STATE_COLLAPSED, , .

. :

bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(@NonNull View bottomSheet, int newState) {
        if (newState == BottomSheetBehavior.STATE_EXPANDED) {
            bottomSheetBehavior.onLayoutChild(coordinatorLayout,
                                            bottomSheetView,
                                            ViewCompat.LAYOUT_DIRECTION_LTR);
        }
    }
    ........
}

, Bottomsheet . .

, Google Map?

, , Bottomsheet STATE_COLLAPSED. , , ​​ .

: STATE_COLLAPSED , ?

+4
2

24.0.0 .

Android, .

0

- , .

mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull final View bottomSheet, int newState) {
            bottomSheet.post(new Runnable() {
                @Override
                public void run() {
                    //workaround for the bottomsheet  bug
                    bottomSheet.requestLayout();
                    bottomSheet.invalidate();
                }
            });
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    });
+1

All Articles