반응형
GradientDrawable을 이용하여 View의 코너가 라운드 처리된 배경이미지 적용하기
layout_test.xml 선언
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="하얀글자"
android:gravity="center"
android:layout_marginBottom="@dimen/view_margin"
android:layout_marginTop="@dimen/view_margin"
android:layout_marginLeft="@dimen/view_margin_side"
android:layout_marginRight="@dimen/view_margin_side"
android:textSize="14dp"
android:singleLine="true"/>
</LinearLayout>
java 코드상에서 View mTestView 를 선언하고 위 layout을 inflate하여 연결함
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColor(Color.parseColor("#2980B9"));
gradientDrawable.setCornerRadius(100);
mTestView.setBackground(gradientDrawable);
//mTestView 내부에 TextView를 넣고 글자를 하얀색으로 표시
TextView textView = mTestView.findViewById(R.id.text);
passNumTextView.setText("하얀글자");
passNumTextView.setTextColor(Color.WHITE);
GradientDrawable 을 생성하고 배경색을 지정
코너의 radius를 적용하고 원하는 View에 background 로 설정
반응형
'코딩하기 > Android' 카테고리의 다른 글
ViewStub을 통한 뷰 로딩 개선 : 안드로이드 성능 개선 #1 (1) | 2023.10.23 |
---|---|
안드로이드 성능 문제 해결을 위해(오늘밤도 글렀..) (0) | 2022.02.23 |
Debugging(2) - 안드로이드 함수 수행 시간 체크 (0) | 2021.04.07 |
Debugging(1) - 콜스택을 이용한 디버깅(누가 내 치즈를 옮겼을까?) (0) | 2021.04.07 |
[Android Permission] 다른 앱 위에서 View 생성 할수 있는지 권한 체크하기 (0) | 2019.09.01 |