300x250
반응형

현재 설정 관련 레이아웃을 만들다가 표시해주는 상자를 곡선으로 그리고 싶었다.

아무래도 더 이쁘기도 하고 벤치마킹하는 유튜브나 다른 플레이어들도 코너를 많이 적용 했기 때문이다.

 

먼저. 나는 constraintLayout을 사용하는데 이 contraintLayout에 corner를 적용하고 싶다.

먼저 일반적으로 사용 할때.. 이렇게 사용 하였음.

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="@dimen/_180sdp"
        android:layout_height="wrap_content"
        android:background="#212121"
        android:visibility="visible"
        android:layout_marginBottom="@dimen/_10sdp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">
        
        <TextView
           ......
        />
</androidx.constraintlayout.widget.ConstraintLayout>

자 이런식으로 한 후에 실행을 시키면 단순히 네모난 모양으로 출력이 된다.

나는 네모난 모양을 곡선으로 변경하고 싶을때 다음과 같이 사용 하였다.

 

view_card.xml

<?xml version="1.0" encoding="utf-8"?><!-- 다이얼로그 배경 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
    <solid android:color="#383838" />
</shape>

위에 내용은 corner를 그려주는 레이아웃이다. 이 레이아웃을 contraintLayout에 background에 적용하면된다.

여기서 참고 할 것은. view_card.xml은. drawable아래에 생성을 해주어야한다!!!

 

아래와 같이 적용하면 이제 네모가 아닌 코너가 만들어진 상태로 화면에 보여준다.

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="@dimen/_180sdp"
        android:layout_height="wrap_content"
        android:background="@drawable/view_card"
        android:visibility="visible"
        android:layout_marginBottom="@dimen/_10sdp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">
        
        <TextView
           ......
        />
</androidx.constraintlayout.widget.ConstraintLayout>

constraintLayout에 background="#212121" -> @drawable/view_card 로 변경하면 끝!

728x90

+ Recent posts