【发布时间】:2016-07-14 23:23:32
【问题描述】:
TL;DR:Bottomsheet 中的 TextView 在 Bottomsheet 第一次展开时未显示环绕的多行文本,但在折叠后会自行调整。
所以我正在使用来自design-23.2.1 库的底部表。
我的布局文件如下所示:
<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>
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>
问题是每当Bottomsheet 设置为STATE_EXPANDED 第一次,TextView 是单行并且文本被换行,并且没有省略号… 在行结束。
那么设置为STATE_COLLAPSED后,TextView的高度就可以了,多行也正常。
我知道在设置为STATE_COLLAPSED 之后发生了高度重新布局,因为我将它从折叠状态中滑动并且多行已经存在。
提供了解决方法here。我跟着它并添加了这个:
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 第一次扩展时,它确实重新调整了高度。然而,它在展开动画完成后突然发生。
有没有办法像谷歌地图一样调整展开动画前的高度?
更新
我发现这个问题是因为我在扩展之前将Bottomsheet设置为STATE_COLLAPSED。如果没有设置,那么问题就消失了,并且第一次正确调整了高度。
现在我的问题是:为什么在扩展之前将其设置为 STATE_COLLAPSED 会导致该问题?
【问题讨论】:
-
你试过最新版本(目前是24.0.0)吗?
标签: android android-design-library bottom-sheet