开发者

9patch image with only horizontal scaling

How do I create a 9Patch image that only scales horizontally? 开发者_运维百科I don't want it to scale vertically. I am not able to create such a 9 PNG.

I tried the article http://radleymarx.com/blog/simple-guide-to-9-patch/ but their method is not working. When I skip the left guide, it gives an error in Eclipse.

I am trying to scale this image horizontally, to create a header bar.


Well, you could mark the vertical scaling as some part of your image which is transparent. May be just near the top and bottom edges. Only those parts would scale vertically. The other vertical section would stay the same.


You could try using a tiled drawable instead of a 9patch:

You create a new drawable via xml, using the non-9patch version of your image, then set the tileMode to repeat. You can then set this new drawable as the background of your header, and it should display as you've described.

http://androidblogger.blogspot.com/2009/01/how-to-have-tiled-background-cont.html


Even if this Question has been answered a few years ago, I got another solution for myself. I tried to have some Textviews in a vertical LinearLayout, all with the same with but a variable height ( depending on their content ).

My solution:

android:paddingLeft="60dp"
android:paddingRight="60dp"

( If you want your Textviews slimmer, than add a higher padding value )

In the LinearLayout: android:paddingLeft="60dp" android:paddingRight="60dp"

And set its children ( the textviews ):

  • the 9patch file as backgroud

  • android:layout_width="match_parent"

  • android:layout_height="wrap_content"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜