问题描述
用户应首先翻转卡片并查看背面,然后向左或向右滑动。有人知道如何在Kotlin中结合翻转面板和滑动吗?
翻盖看起来像这样:https://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/cardflip.html
滑动看起来像这样:https://github.com/yuyakaido/CardStackView
预先感谢和亲切问候。
解决方法
我想在Kotlin中为Android创建一个堆栈:
-
哪个项目的位置相同(无偏移)。例如,像火种。一个人只看到堆栈的第一项/图像。
-
我想添加翻页并查看卡的背面。像这样:https://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/cardflip.html
-
翻转后,我想通过向左或向右滑动来移除卡。
到目前为止,我有一个带有以下代码的堆栈:
MainActivity
package com.example.stackview
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
val itemList = listOf<Int>(R.drawable.ic_launcher_background,R.drawable.ic_launcher_background,R.drawable.ic_launcher_background)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val stackAdapter = StackAdapter (this,itemList)
stack_view.adapter = stackAdapter
}
}
StackAdapter
package com.example.stackview
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
class StackAdapter(val context: Context,val list: List<Int>): BaseAdapter(){
override fun getView(position: Int,convertView: View?,parent: ViewGroup?): View {
val view = LayoutInflater.from(context).inflate(R.layout.item,parent,false)
val item = view.findViewById<ImageView>(R.id.image) as ImageView
item.setImageResource(list[position])
return view
TODO("Not yet implemented")
}
override fun getItem(position: Int): Any {
return list[position]
TODO("Not yet implemented")
}
override fun getItemId(position: Int): Long {
return position.toLong()
TODO("Not yet implemented")
}
override fun getCount(): Int {
return list.size
TODO("Not yet implemented")
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity"
android:orientation="horizontal">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<StackView
android:id="@+id/stack_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:loopViews="true"
android:animateLayoutChanges="true"/>
</FrameLayout>
</LinearLayout>