小编Pei*_*ike的帖子

Android Bottomsheet TextView 高度未在第一次展开时调整

TL;DR:TextView在Bottomsheet第一次Bottomsheet展开时不显示换行的多行文本,但在折叠后自行调整。

所以我正在使用design-23.2.1库中的Bottomsheet 。

我的布局文件如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

的内容Bottomsheet基本上是一个列表:

<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>
Run Code Online (Sandbox Code Playgroud)

问题是当Bottomsheet设置为STATE_EXPANDED第一次时,TextView单行和文本被换行,并且…行尾没有省略号。

然后在它设置为 之后STATE_COLLAPSED,TextView的高度很好并且正确地多行了。

我知道高度重新布局发生在设置为之后,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); …
Run Code Online (Sandbox Code Playgroud)

android android-design-library bottom-sheet

6
推荐指数
1
解决办法
1422
查看次数