从版本23.4.0切换到
Android Design Support库的24.2.1版之后,BottomSheetBehavior停止了为我工作. BottomSheet显示为打开,并且在调用setState时不关闭(BottomSheetBehavior.STATE_COLLAPSED).这不会发生在BottomSheetBehavIoUr按预期为我工作的设计库的23.4.0上.
版本24中是否有任何更改需要使用BottomSheetBehavior?
这是我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="Open Bottom Sheet"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/close_button"
android:text="Close Bottom Sheet"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:background="@android:color/holo_green_light"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>
这是我正在使用的活动代码:
public class ScrollingActivity extends AppCompatActivity implements View.OnClickListener {
private View m_bottomSheet;
private BottomSheetBehavior m_behavIoUr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
m_bottomSheet = findViewById(R.id.bottom_sheet);
m_behavIoUr = BottomSheetBehavior.from(m_bottomSheet);
((Button)findViewById(R.id.button)).setonClickListener(this);
((Button)findViewById(R.id.close_button)).setonClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button:
m_behavIoUr.setState(BottomSheetBehavior.STATE_EXPANDED);
break;
case R.id.close_button:
m_behavIoUr.setState(BottomSheetBehavior.STATE_COLLAPSED);
break;
}
}
}
任何意见,将不胜感激.
解决方法
m_behavIoUr.setPeekHeight(0);
它默认为“peek”状态,所以如果你不想要它看,你需要将peek高度设置为0.