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 :(

Person
  • 345
  • 2
  • 4
  • 11

3 Answers3

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" />
Ahmed Nawaz
  • 1,634
  • 3
  • 21
  • 51
  • when I'm doing this the lines fills the whole image no just red part of the image – Person Jun 10 '14 at 09: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. – Ahmed Nawaz Jun 10 '14 at 09:53
  • @Person you can find code for rounding corners here http://stackoverflow.com/a/3292810/1770916 – Ahmed Nawaz Jun 10 '14 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

Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
  • Thank you @Rod_Algonquin. Is there any other solution to make this. Can I do it with drawable xml's? – Person Jun 10 '14 at 09: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 – Rod_Algonquin Jun 10 '14 at 09: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);
pskink
  • 23,874
  • 6
  • 66
  • 77