[2024. 01. 11] 개인 과제(진행)

Gahyeon Lee·2024년 1월 11일
0

TIL

목록 보기
43/47
post-thumbnail

💡 상품 이름은 최대 두 줄이고, 그래도 넘어가면 뒷부분에 …으로 처리

android:maxLines="2"
android:ellipsize="end"

💡 RecyclerView에 회색 구분선 그리기

ListView는 xml 코드에서 자체적으로 하단 구분선을 그리는 기능이 있지만, RecyclerView는 ItemDecoration을 사용해서 그려줘야 한다. 처음에는 xml의 View로 그렸는데 그렇게 하면 다음과 같은 문제가 생긴다고 한다.

  • 퍼포먼스에 영향을 준다

  • 좌우 슬라이드 시 하단 구분선이 같이 움직인다.

  • 각각 구분선을 통제할 수 없게 된다.

    -> MainActivity에 ItemDecoration 추가

    val decoration = DividerItemDecoration(this, VERTICAL)     // VERTICAL은 지정한 layoutmanager에 따라 import해주기.
     binding.recyclerView.addItemDecoration(decoration)

💡 1000단위로 가격 콤마 처리하기 : DecimalFormat 사용

val decimal = DecimalFormat("#,###")
 binding.tvPrice.text = decimal.format(it.itemPrice) + "원"
  • Suppress:Add @SuppressLint("SetTextI18n")이라는 워닝은 TextView를 string에 지정하지 않고 하드코딩하는 경우에 발생한다. 무시해도 문제가 되진 않지만 함수 상단에 @SuppressLint("SetTextI18n")을 추가해 주거나 텍스트를 string으로 저장하면 워닝이 해결된다.

💡 텍스트에 밑줄 긋기

  1. strings.xml에서 태그 주기

    <string name="manner"> <u>매너온도</u> </string>
  2. activity에 코드 넣어주기

    binding.tvManner.paintFlags = Paint.UNDERLINE_TEXT_FLAG

💡 이미지 모서리를 라운드 처리하기

1. cardView

<androidx.cardview.widget.CardView
      android:id="@+id/iconItemCardView"
      android:layout_width="@dimen/icon_size"
      android:layout_height="@dimen/icon_size"
      android:layout_marginStart="16dp"
      app:cardCornerRadius="8dp"
      app:cardElevation="0dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent">

      <ImageView
          android:id="@+id/iconItem"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center_vertical"
          android:adjustViewBounds="true"
          android:scaleType="centerCrop"
          android:src="@drawable/sample1" />
          
  </androidx.cardview.widget.CardView>

2. clipToOutLine

  • shape xml 파일 만들기
    <?xml version="1.0" encoding="utf-8"?>
     <shape xmlns:android="http://schemas.android.com/apk/res/android">
         <corners android:radius="10dp" />
     </shape>
  • 이미지뷰 백그라운드에 shape 적용하고, 이미지뷰에 clipToOutLine = true로 지정
    <ImageView
          ...
          android:background="@drawable/round"
          android:clipToOutline="true"
          ... />
profile
코린이 강아지 집사🐶

0개의 댓글