Android custom form

I know that you can make a form that looks something like this: enter image description here

But I do not know how to start with it. Can I do this as a form? or do i need to do something else?

BR

+3
android shape
source share
4 answers

Oh look at this, I was wrong - gradients are not a problem:

import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.LinearGradient; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader; import android.view.View; public class ButtonShadow extends View { public ButtonShadow(Context context) { super(context); } @Override public void onDraw(Canvas canvas) { RectF space = new RectF(this.getLeft(), this.getTop(), this.getRight(), this.getBottom()); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShader(new LinearGradient(0, getWidth(), 0, 0, Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR)); canvas.drawArc(space, 180, 360, true, paint); Rect rect = new Rect(this.getLeft(),this.getTop() + (this.getHeight() / 2),this.getRight(),this.getBottom()); canvas.drawRect(rect, paint); } } 

Read more about gradient bays here: How to fill the Path in Android with a linear gradient?

+4
source share

Refer to this document for details , and you need to use the Layer List .

Here is the code according to your image:

custom_layer_list.xml

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/topCircular" /> <item android:drawable="@drawable/rect" android:top="20dp" /> </layer-list> 

topCircular.xml

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#000000" /> <corners android:topLeftRadius="25dp" android:topRightRadius= "25dp" /> </shape> 

rect.xml

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#000000" /> </shape> 
+4
source share

You can define it in xml in the shapes file, but it’s easier to make a simple 9-patch graphic, then you can easily configure how and where the curved and straight segments will stretch.

See http://developer.android.com/tools/help/draw9patch.html for details

EDIT

See more details about shapes here: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

+1
source share

You can only do this with the form:

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#000000" /> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:topLeftRadius="90dip" android:topRightRadius="90dip" android:bottomLeftRadius="0dip" android:bottomRightRadius="0dip" /> </shape> 
+1
source share

All Articles