Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将底部图纸卡视图转换为顶部图纸卡视图_Android_Android Layout_Kotlin_Android Cardview_Android Coordinatorlayout - Fatal编程技术网

Android 将底部图纸卡视图转换为顶部图纸卡视图

Android 将底部图纸卡视图转换为顶部图纸卡视图,android,android-layout,kotlin,android-cardview,android-coordinatorlayout,Android,Android Layout,Kotlin,Android Cardview,Android Coordinatorlayout,我能够创建一个底部的卡片视图。我正在尝试将我拥有的转换为顶部的卡片视图(当用户单击按钮时,卡片视图应该显示在顶部,而不是底部)。感谢您的帮助 SheetBehaviorActivity.kt class SheetBehaviourActivity : AppCompatActivity() { lateinit var sheetBehavior: BottomSheetBehavior<*> override fun onCreate(savedInstanc

我能够创建一个底部的卡片视图。我正在尝试将我拥有的转换为顶部的卡片视图(当用户单击按钮时,卡片视图应该显示在顶部,而不是底部)。感谢您的帮助

SheetBehaviorActivity.kt

class SheetBehaviourActivity : AppCompatActivity() {

    lateinit var sheetBehavior: BottomSheetBehavior<*>

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val btn: Button = this.findViewById(R.id.testing_bottom_sheet_btn)

        btn.setOnClickListener {
            if (sheetBehavior.state != BottomSheetBehavior.STATE_EXPANDED) {
                sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
                btn.text = "Close sheet"
            } else {
                sheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
                btn.text = "Expand sheet"
            }
        }

        val sheetContainer = findViewById<CardView>(R.id.bottom_sheet_container)

        sheetBehavior = BottomSheetBehavior.from(sheetContainer)
        sheetBehavior.isHideable = true
        sheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN

    }
}
类活动:AppCompatActivity(){
lateinit变量sheetBehavior:BottomSheetBehavior
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btn:Button=this.findViewById(R.id.testing\u bottom\u sheet\u btn)
btn.setOnClickListener{
if(sheetBehavior.state!=BottomSheetBehavior.state_展开){
sheetBehavior.state=底部sheetBehavior.state\u已展开
btn.text=“关闭工作表”
}否则{
sheetBehavior.state=BottomSheetBehavior.state\u隐藏
btn.text=“展开工作表”
}
}
val sheetContainer=findViewById(R.id.底部\u板材\u容器)
sheetBehavior=BottomSheetBehavior.from(sheetContainer)
sheetBehavior.isHideable=true
sheetBehavior.state=BottomSheetBehavior.state\u隐藏
}
}
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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.SheetBehaviourActivity">

    <Button
        android:id="@+id/testing_bottom_sheet_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Expand Sheet" />

    <android.support.v7.widget.CardView
        android:id="@+id/bottom_sheet_container"
        android:layout_width="match_parent"
        app:cardCornerRadius="20dp"
        app:cardBackgroundColor="@android:color/holo_blue_light"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
        android:layout_height="300dp"/>

</android.support.design.widget.CoordinatorLayout>

这是
TopSheetBehavior
在我的情况下,实现工作很好

以下是您的操作方法:

<?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"
    tools:context=".activities.SheetBehaviourActivity">

    <Button
        android:id="@+id/testing_bottom_sheet_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Expand Sheet" />

    <android.support.v7.widget.CardView
        android:id="@+id/bottom_sheet_container"
        android:layout_width="match_parent"
        app:cardCornerRadius="20dp"
        app:cardBackgroundColor="@android:color/holo_blue_light"
        app:behavior_hideable="true"
        app:behavior_peekHeight="56dp"
        app:layout_behavior="your.package.components.TopSheetBehavior"/>

</android.support.design.widget.CoordinatorLayout>

TopSheetBehavior
只是替换行为参数