728x90
🟦 CardStackView 사용하기
▶️ CardStackView 사용하기
https://github.com/yuyakaido/CardStackView
- module 수준의 gradle 파일에서 의존 추가
dependencies {
implementation "com.yuyakaido.android:card-stack-view:${LatestVersion}"
}
🟧 activity_main.xml에 cardStackView 영역 잡아놓기
<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"
android:orientation="vertical"
tools:context=".MainActivity">
<com.yuyakaido.android.cardstackview.CardStackView
android:id="@+id/cardStackView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
🟧 item_card.xml 생성
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_margin="20dp"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/profileImageArea"
android:layout_width="match_parent"
android:layout_height="500dp"
android:src="@drawable/no" />
<TextView
android:text="Name"
android:layout_margin="5dp"
android:textSize="30sp"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Age"
android:layout_margin="5dp"
android:textSize="30sp"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="City"
android:layout_margin="5dp"
android:textSize="30sp"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<FrameLayout
android:id="@+id/left_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/no"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"/>
</FrameLayout>
<FrameLayout
android:id="@+id/right_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/ok"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"/>
</FrameLayout>
</androidx.cardview.widget.CardView>
🟧 CardStackAdapter 생성
class CardStackAdapter(val context : Context, val items : List<String>) : RecyclerView.Adapter<CardStackAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardStackAdapter.ViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view: View = inflater.inflate(R.layout.item_card, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: CardStackAdapter.ViewHolder, position: Int) {
holder.binding(items[position])
}
override fun getItemCount(): Int {
return items.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun binding(data: String) {
}
}
}
🟧 MainActivity.kt 에서 Adapter 연결
class MainActivity : AppCompatActivity() {
lateinit var cardStackAdapter : CardStackAdapter
lateinit var manager : CardStackLayoutManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val cardStackView = findViewById<CardStackView>(R.id.cardStackView)
manager = CardStackLayoutManager(baseContext, object : CardStackListener {
override fun onCardDragging(direction: Direction?, ratio: Float) {
}
override fun onCardSwiped(direction: Direction?) {
}
override fun onCardRewound() {
}
override fun onCardCanceled() {
}
override fun onCardAppeared(view: View?, position: Int) {
}
override fun onCardDisappeared(view: View?, position: Int) {
}
})
val testList = mutableListOf<String>()
testList.add("a")
testList.add("b")
testList.add("c")
cardStackAdapter = CardStackAdapter(baseContext, testList)
cardStackView.layoutManager = manager
cardStackView.adapter = cardStackAdapter
}
}
728x90
'App(앱)_관련 공부 모음 > [Android 관련]' 카테고리의 다른 글
📍[오류] Ignoring header X-Firebase-Locale becuase its value was null. (0) | 2022.09.16 |
---|---|
📍[에러] com.google.firebase.FirebaseException: An internal error has occurred. [ API key not valid. Please pass a valid API key. ] 해결 방법 (0) | 2022.09.16 |
java.lang.AbstractmethodError : onChangedStatus() 관련 에러 (0) | 2022.08.26 |
[Android] 에뮬레이터 실행 오류 해결 방법 (0) | 2022.04.09 |
[Android]_구글 로그인 연동하기 (0) | 2022.04.08 |