我尝试使用谷歌支持库制作底片。目标是有一张表:
到目前为止,这么好,简单的东西。还有一个有希望的isHideable()
默认为false。
但是当工作表设置为isHideable
时,底部表格似乎忽略STATE_EXPANDED
(尽管它不会覆盖整个屏幕)。使它不可隐藏的唯一方法是设置一个偷看高度(我不想要)。如果不手动设置高度(或通过布局更改触发器),有没有办法让它扩展和不可隐藏
以下是使用的(超薄)代码:
Activity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View bottomSheet = findViewById(R.id.bottomsheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setHideable(false);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/bottomsheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
app:layout_behavior="@string/bottom_sheet_behavior"
android:background="@android:color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="300dp"
android:text=":) :) :)"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
行为
答案 0 :(得分:1)
到目前为止我发现的最简单但最神圣的方式:
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
bottomSheet.post(new Runnable() {
@Override
public void run() {
behavior.setPeekHeight(bottomSheet.getHeight());
}
});
当然,当需要隐藏它时,请先致电setHideable(true)
。
这只是一种可能导致奇怪行为的解决方法。