Bitmap TileX ONLY

爷,独闯天下 提交于 2019-12-08 05:42:22

问题


I want my image to repeat only in X axis.

I use this code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LinearLayout l = new LinearLayout(this);
    l.setLayoutParams(new LayoutParams(-2, -2));
    BitmapDrawable b = null;
    try {
        b = new BitmapDrawable(getAssets().open("pattern.jpg"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    b.setTileModeX(TileMode.REPEAT);

    l.setBackgroundDrawable(b);

    setContentView(l);
}

When i execute my app, bitmap repeat in X axis but i show something string in Y axis

http://img24.imageshack.us/img24/9027/rgxt.png

If i try to repeat in Y axis, it happens the same but in the X axis.

How can i repeat my image only in X axis without seeing theses vertical "lines"?


回答1:


It appears that your bitmap takes a CLAMP tilemode in Y.

I guess it's the default value.

You should define what you need for the vertical direction, since your image is to small for your background, do you want to repeat it ? or strech it ?

if you don't want any of this, but need simply another color for the space under this image, you should consider adding a one pixel horizontal line at the bottom of the image.

then let the CLAMP tilemode extend this color to the entire background.

more information on this here



来源:https://stackoverflow.com/questions/17422365/bitmap-tilex-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!