Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom shaped Linearlayout with curved side in android

I am trying to make a custom shaped linearlayout like below

enter image description here

I am trying to make only one side curved. Tried with corner radius but it doesn't give the same look as above.

Already tried this background shape as below :-

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#3F51B5" />

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

    <corners
        android:bottomLeftRadius="50dp"
        android:bottomRightRadius="50dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />
</shape>

it rounds only corners and on increasing the value shape is not preserved it gets too circular. I WANT CURVED line and not rounded corners

like image 417
UzUmAkI_NaRuTo Avatar asked Apr 27 '16 11:04

UzUmAkI_NaRuTo


People also ask

How do you add corner radius in XML?

xml version = "1.0" encoding = "utf-8" ?> Step 5: Now go to the activity_main. xml file and add an attribute to that TextView, for which you want to add rounded corners. The attribute is android: background=”@drawable/rounded_corner_view”.

How do you do a horizontal LinearLayout?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .


2 Answers

Its very late already but this is for future seekers. I think vector drawables are the most perfect solution for this. Use below vector as background to get custom shaped bottom curved layout.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="100.0"
android:viewportWidth="200.0">
<path
    android:fillColor="#YOUR_FAVORITE_COLOR"
    android:pathData="M200,0H0v4.5h0v75.8h0c17.8,10.2 56,17.2 100.5,17.2c44.5,0 81.6,-7 99.5,-17.2h0V4.5h0V0z" />

like image 139
Alex Chengalan Avatar answered Oct 13 '22 22:10

Alex Chengalan


Create a shape file in drawable folder e.g: my_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
   <corners
      android:bottomLeftRadius="100dp"
      android:bottomRightRadius="100dp"
      android:topLeftRadius="0dp"
      android:topRightRadius="0dp" />
   <padding
      android:bottom="0dp"
      android:left="0dp"
      android:right="0dp"
      android:top="0dp" />
   <stroke
      android:width="0.5dp"
      android:color="@color/theme_red" />
  <solid android:color="@color/white" />
</shape> 

then add this shape in your layout as a background. e.g:

<LinearLayout
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/my_shape"
     android:orientation="horizontal">             
</LinearLayout>
like image 10
Masum Avatar answered Oct 14 '22 00:10

Masum