개발 창고/Android

[Android] How to make round box

로이제로 2024. 2. 13. 08:00
반응형

Sometimes when you create a button, you want to create a list or a specific box to display the information inside.

In the case of round boxes through images, it is the neatest to apply mainly through xml design because it has the disadvantage of being fixed size or breaking image. (From what I know...)

It's very simple to use, but it's a waste of memory to use, so it's best to leave it and copy it


 

How to make round box

 Create one border.xml in the res > drawable folder and copy the source below.

res > drawable > New > Drawable Resource File
border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent"/>
    <stroke
        android:width="1dp"
        android:color="#9e8181"/>
    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp"/>
    <corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp"/>
</shape>

 

 Apply the created border image as the background of the Relative Layout.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="@drawable/border"
    android:layout_margin="20dp"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Examples of text box utilization."
</RelativeLayout>

Example of Application to RelativeLayout


Description

Android:shape can be created in four forms: [rectangle/oval/line/ring]

  • rectangle: square
  • oval: circle
  • line: linear
  • ring: cylindrical

 

<solid>

 : In rectangle, solid can only be applied to the interior color of the rectangle (android:color).

 - color:inner color of rectangle

 

<stroke>

 : In rectangle, stroke is the setting for the square border.

 - width: thickness of border line

 - color:color of border line

 - dashGap: If you want to apply the border as a dotted line rather than a solid, the interval between the points

 - dashWide: the length of the point if you want to apply the border as a dotted line rather than a solid line

 

<padding>

 : A space inside a square that means the spacing between letters and borders when used in buttons.

 

<cornors>

: It can be applied if you make a button with rounded corners. Depending on the size, it can even be circular.

 

<gradient>

: This is possible if the gradient is applied inside the button.


[Android] How to make Round Box

🇰🇷 Korean

2020.07.23 - [개발 창고/Android] - [Android] round box 만들기

 

[Android] round box 만들기

가끔 버튼을 만들다 보면 리스트나 특정 박스를 만들어 내부에 정보를 표기하고 싶은 경우가 생기곤 합니다. 이미지를 통한 라운드 박스의 경우 고정 크기 아니면 이미지가 깨지는 단점이 있기

royzero.tistory.com

 

반응형