开发者

9patch drawable 1px black line visible & content positioning

I've got following 9patch, which I got thanks to nice people who answered my previous question:

9patch drawable 1px black line visible & content positioning

I use it for background in relative layout and TextView and got following. Thats for RelativeLayout:

  <RelativeLayout
        android:id="@+id/relativeHeader"
   开发者_如何转开发     android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:orientation="horizontal"
        android: background="@drawable/cap_stack">

9patch drawable 1px black line visible & content positioning

And for TextView:

<TextView
       android:paddingTop="5dp"
       android:gravity="center_vertical"
       android:layout_width="fill_parent"
       android:layout_height="22dp"
       android:background="@drawable/cap_stack"
       android:textStyle="bold"
       android:textColor="#FFFFFF"/>

9patch drawable 1px black line visible & content positioning

As you can see, I got 1px wide line visible in both cases. And in case of TextView text is not placed in the center vertical. How can I fix it(is it drawable problem or xml)? Will appreciate any help


You shouldn't have a solid border all the way around. The top and left borders define the stretch areas (you only need one pixel on the top for stretching, and you want JUST the gradient to stretch on the vertical axis). The bottom and right borders define the content area, so you want to leave some padding as well. The four corner pixels should never be filled.

Try this one:

9patch drawable 1px black line visible & content positioning

or this one:

9patch drawable 1px black line visible & content positioning


try this for your textview, the problem is your layout_height You are wanting the textSize attribute instead. Also, notice I used the SP unit instead of DP as that is what the docs recommend for text size values. I hope this helps!

<TextView
   android:paddingTop="5dp"
   android:gravity="center_vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:textSize="22sp"
   android:background="@drawable/cap_stack"
   android:textStyle="bold"
   android:textColor="#FFFFFF"/>


Did you named your image as cap_stack.9.png? It seems android is not processing it as 9patch.


android:gravity="center_vertical" works with LinearLayout Only , Use Layout_centerVertical=true for relativeLayout .

and that lines on border seems part of your image , not seeing any other possibility //////so rechecking image once might be helpful .

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜