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
    – pskink
    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" />
3
  • when I'm doing this the lines fills the whole image no just red part of the image
    – Person
    Jun 10, 2014 at 9:49
  • 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. Jun 10, 2014 at 9:53
  • @Person you can find code for rounding corners here stackoverflow.com/a/3292810/1770916 Jun 10, 2014 at 10:03
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
  • Thank you @Rod_Algonquin. Is there any other solution to make this. Can I do it with drawable xml's?
    – Person
    Jun 10, 2014 at 9:53
  • @Person just set it directly to a view so it will scale equally.. If those lines where not there you can make a 9patch Jun 10, 2014 at 9:58
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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.