1

I want to make a button like this but I cant Because when I convert it to 9patch the lines of button is scaling. But i want to repeat and full the button with lines
this is the original image this is the original image


i want to be like this i want to be like this


But it looks like this :( But it looks like this :(

1
  • use a ShapeDrawable, setup a ShaderFactory that returns a BitmapShader Commented Jun 10, 2014 at 9:56

3 Answers 3

1

Create a Bitmap Resource and repeat texture.

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/ab_texture_tile_apptheme" android:tileMode="repeat" /> 
Sign up to request clarification or add additional context in comments.

3 Comments

when I'm doing this the lines fills the whole image no just red part of the image
This is because of your round corners. I think you have to do some thing in coding. Create Bitmap by repeating texture and then round corners of image in java.
@Person you can find code for rounding corners here stackoverflow.com/a/3292810/1770916
1

You only use 9patch when you scale some part of it. Based from your example image and you quote lines of button is scaling that is because of the 9patch.

Solution

Dont use 9patch just set it as a background Drawable/imageSource in your desire view

2 Comments

Thank you @Rod_Algonquin. Is there any other solution to make this. Can I do it with drawable xml's?
@Person just set it directly to a view so it will scale equally.. If those lines where not there you can make a 9patch
1

try this:

final float r = 32; float[] outerRadii = { r, r, r, r, r, r, r, r }; ShapeDrawable d = new ShapeDrawable(new RoundRectShape(outerRadii, null, null)); ShaderFactory factory = new ShaderFactory() { @Override public Shader resize(int width, int height) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Shader shader = new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT); Matrix localM = new Matrix(); localM.postRotate(45); shader.setLocalMatrix(localM); return shader; } }; d.setShaderFactory(factory); someView.setBackgroundDrawable(d); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.