Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- firebase
- EditText
- lifecyclescope
- FRAGMENT
- Kotlin
- 안드로이드 스튜디오
- 랜덤ID
- ViewModel
- 코틀린
- 뷰바인딩
- firebasefunctions
- ButtonWithButton
- button
- 밑줄
- RealtimeDB
- textview
- nav_graph
- MaterialButton
- 안드로이드
- Dialog
- ROOM
- BottomSheetDialog
- ArrayList
- 안드로이드스튜디오
- androidstudio
- OutlinedButton
- Android
- Activity
- Imageview
- 팝업액티비티
Archives
- Today
- Total
안드로이드 앱 개발
Expandable Cardview (카드뷰 접었다가 펴는 기능) - Kotlin 본문
먼저, xml에서
default로 보여지는 애들과 숨겨져 있는 애들을 구분한다.
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/customer_number_tv"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
app:elevation="0dp">
<!--This is a ConstraintLayout for the entire CardView
including the expandable portion-->
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/fixed_layout"
android:layout_width="match_parent"
android:layout_height="30dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="방문이력"
android:textColor="@color/mainGrey"
android:fontFamily="@font/notosanscjkkrmedium"
android:includeFontPadding="false"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="10dp" />
<ImageView
android:id="@+id/history_expand_iv"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="10dp"
android:adjustViewBounds="true"
android:scaleType="center"
app:srcCompat="@drawable/outline_expand_more_black_36"
app:tint="@color/mainGrey"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/hiden_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fixed_layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Database Management"
android:textColor="#000000"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Database Management"
android:textColor="#000000"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Database Management"
android:textColor="#000000"
android:textSize="20dp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
2. 다음 코드에서
클릭 이벤트 처리
binding.fixedLayout.setOnClickListener {
if (binding.hidenView.visibility == View.VISIBLE){
TransitionManager.beginDelayedTransition(binding.cardview,
AutoTransition())
binding.hidenView.visibility = View.GONE
binding.historyExpandIv.setImageResource(R.drawable.arrow_down_float)
} else{
TransitionManager.beginDelayedTransition(binding.cardview,
AutoTransition())
binding.hidenView.visibility = View.VISIBLE
binding.historyExpandIv.setImageResource(R.drawable.arrow_up_float)
}
}