gpt4 book ai didi

android - 仅在单击按钮时才需要显示 Bottom Sheet 行为?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:42:35 27 4
gpt4 key购买 nike

我已经使用 appcompat-v7:23.2.1 实现了 Bottom Sheet 。一切正常,但唯一的问题是当我向上拖动布局时, Bottom Sheet 出现了。我没有当 Bottom Sheet 未显示在屏幕上时,希望在布局上向上拖动时显示 Bottom Sheet 。

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/DarkGray"
tools:context=".bottom_sheets.grid.BottomSheetGridActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<Button
android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show view" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_sheet1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_marginBottom="8dp"
app:layout_behavior="@string/bottom_sheet_behavior">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:background="#fff"
/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

主要 Activity

  @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bottom_grid);
Button btnView = (Button) findViewById(R.id.btnView);
View bottomSheet = findViewById(R.id.bottom_sheet1);
behavior = BottomSheetBehavior.from(bottomSheet);
btnView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});

behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change

}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
}
});

RecyclerView listRecyclerView = (RecyclerView) findViewById(R.id.recyclerView1);
listRecyclerView.setHasFixedSize(true);
listRecyclerView.setLayoutManager(new LinearLayoutManager(this));
RecyclerItemAdapter recyclerItemAdapter = new RecyclerItemAdapter(createItems(), this);
listRecyclerView.setAdapter(recyclerItemAdapter);
}

上面的代码将在点击时显示 Bottom Sheet ,但在布局上向上拖动时也会显示工作表。我是否遗漏了什么。请帮助我!

最佳答案

感谢@oguzhand

 behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
}
});

我现在可以在未显示时禁用 Bottom Sheet 行为。

关于android - 仅在单击按钮时才需要显示 Bottom Sheet 行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36372601/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com