0

用户应首先翻转卡片并查看背面,然后向左或向右滑动。有人知道如何在 Kotlin 中结合翻转甲板和滑动吗?

翻转甲板看起来像这样:https ://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/cardflip.html

滑动看起来像这样:https ://github.com/yuyakaido/CardStackView

在此先感谢和亲切的问候。

4

1 回答 1

0

我想在 Kotlin 中为 Android 创建一个堆栈:

  1. 它的项目在同一位置(没有偏移)。例如,像 Tinder。一个人只看到堆栈的第一个项目/图像。

  2. 我想添加翻转并查看卡片的背面。像这样:https ://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/cardflip.html

  3. 翻转后,我想通过向左或向右滑动来移除卡片。

到目前为止,我有一个包含以下代码的堆栈:

主要活动

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
    }
}

堆栈适配器

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>
于 2020-09-17T11:53:08.257 回答