How to create different type shape in android javaAndroid Development
December 21, 20201 minuteuserPankaj Valani
How to create different type shape in android java
Hello, wonderfully friends today in this blog in learning in android XML file creating different type 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
  •  flow below image steps:


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" />

  <solid android:color="#CFCFCF" />

  <padding
    android:bottom="0dp"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp" />

  <size
    android:height="60dp"
    android:width="270dp" />
 
</shape>


Corners:

  • The below image is showing the shape corner radius
Solid :

  • -Solid means shape inner color “#CFCFCF”

Padding:

- There is always confusion developer 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:

  •  Its very simple shape width - height