Android: 9-patch repeat pattern instead of stretching

拈花ヽ惹草 提交于 2019-12-03 05:30:12

问题


I have a 9-patch image file which looks like this:

When I use it it appears like this:

What I actually wanted to achieve is the complete dot in the center repeated instead of stretched. I hope that it's possible.


回答1:


I think it's not possible using 9-Patch to make repeated patterns (only stretching certain area), perhaps you could find more about it in official documentation




回答2:


...

Correction: If you want the orange dots to repeat, you will not succeed using 9 patch. 9 patch can only stretch the part you told it to stretch and leave untouched, the remaining areas. There is no repeat mode with 9 patch PNG.

You might want to look into Bitmap class. There is a tileMode you might be able to use for your problem here.

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/stripe_bg"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
        />



回答3:


First make sure you save your 9 patch image as your_image_name.9.png and store it in the res/drawable folder. Then in your xml just set the layout background with-- android:background="@drawable/your_image_name" and that should work. If it's still not working can you post your layout xml?



来源:https://stackoverflow.com/questions/3636251/android-9-patch-repeat-pattern-instead-of-stretching

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