sách gpt4 ăn đã đi

android - BottomSheet 在按钮点击时跳跃

In lại Tác giả: Walker 123 更新时间:2023-11-30 05:09:49 26 4
mua khóa gpt4 giày nike

我有一个包含产品详细信息卡片的 BottomSheet。问题是,当我在 Bottom Sheet 处于 展开 状态时单击产品详细信息上的 + hoặc - 按钮时,它跳下来

当它处于关闭状态并且我单击按钮时它不会跳转,只有当它处于展开(完全打开)状态时才会发生

我附上了一张 GIF 以显示到底发生了什么

nhập mô tả hình ảnh ở đây

这是代码

scan_sheet.xml



xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:animateLayoutChanges="false"
android:background="@drawable/bottom_sheet_dialog_fragment"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="100dp"
app:layout_behavior="studio.monotype.storedemo.BottomSheetBehavior">

<>
layout="@layout/hero_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<>
android:id="@+id/divider_view"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_marginStart="24dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="24dp"
android:background="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/hero_item" />

<>
layout="@layout/related_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider_view"
tools:layout_editor_absoluteX="0dp" />

ScanActivity.kt (已简化以仅显示必要的内容)

class ScanActivity : AppCompatActivity() {


private lateinit var bottomSheet: BottomSheetBehavior<*>


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scan)

setupBottomSheet()

showSheet()
}




private fun setupBottomSheet() {
bottomSheet = BottomSheetBehavior.from(bottom_sheet)
bottomSheet.isHideable = true
bottomSheet.skipCollapsed= true
bottomSheet.isDraggable = true
bottomSheet.state = BottomSheetBehavior.STATE_HIDDEN
bottomSheet.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback {
override fun onSlide(bottomSheet: View, slideOffset: Float) {
}

@SuppressLint("SwitchIntDef")
override fun onStateChanged(sheet: View, newState: Int) {
when (newState) {
BottomSheetBehavior.STATE_HIDDEN -> {
codeScanner.startPreview()
}
}
}

})


plus_btn.setOnClickListener {
var qty= qty_tv.text.toString().toInt()
qty++
qty_tv.text =qty.toString()
}

minus_btn.setOnClickListener {
var qty= qty_tv.text.toString().toInt()
if(qty!=0)
{
qty--
}
qty_tv.text =qty.toString()
}


}

private fun showSheet() {
bottomSheet.state = BottomSheetBehavior.STATE_EXPANDED
}


}

câu trả lời hay nhất

看来google工程师给出了正确答案

Seems like something is going on because you are setting android:layout_gravity="bottom" on the view with the BottomSheetBehavior. You should remove that line.

对我的案子有帮助

关于android - BottomSheet 在按钮点击时跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53930666/

26 4 0
Đề xuất bài viết: java 2D 绘图
Đề xuất bài viết: java - Spring MVC : JSP or JSON view in Controller method depending on request
Đề xuất bài viết: java - 选择平台即服务
Đề xuất bài viết: c++ - 在线程之间共享数据
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress