How to create different type shape in android java

Android Development
October 07, 20201 minuteuserPankaj Valani
How to create different type shape in android java

Hello, wonderful friends today in this blog on learning in android XML files creating different types of shape creating. A shape is an XML file that defines a geometric shape, including strokes, colors, and gradients

First Creating .xml file:

  1. Open android studio
  2. Go to drawable
  3. Right-click drawable menu

Follow below image steps:

2020-12-18-5fdc731fe3b6a

Now friend starts coding:

  • Creating a capsule shape flow below code:
<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:radius="60dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp"/>

Corners:

The below image is showing the shape corner radius

Solid:

Solid means shape inner color “#CFCFCF”

Padding:

There is always developer confusion between padding and margin. Both provide extra space/gap inside or outside the container. In simple words, margin means to push outside, whereas padding means to push inside.

Size:

It's very simple shape width - height