开发者

9patch drawable as RelativeLayout background issue

I've got RelativeLayout as a header in Activity and I want it to have 9.png drawable as a background. Here is drawable:

9patch drawable as RelativeLayout background issue

What I receive:

9patch drawable as RelativeLayout background issue

As you can see - there is extra spacing.

Here I use RGB color as a backgroud(and how I want it look with 9patch):

9patch drawable as RelativeLayout background issue

Is it me doing something funny or it's normal for 9patch to look like that?

UPDATED WITH CODE

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout
    android:id="@+id/relativeTop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    <--THIS IS IT-->
    android:background="@drawable/cap">
    <--THIS IS IT-->
    <Button
      android:id="@+id/btnSearchMainReset"
      android:text="@string/btnSearchMainReset_text"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_alignParentRight="true"
    />
  </RelativeLayout>
  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/relativeTop">
  <RelativeLayout
      android:paddingLeft="5dp"
      android:paddingRight="5dp"
      android:layout_below="@id/relativeTop"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#FFFFFF">
      <Button
        android:id="@+id/btnSearchMainSearch"
        android:text="@string/btnSearchMainSearch_text"
        android:textSize="20sp"
     开发者_开发知识库   android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:width="200dp" 
      /> 
      <RelativeLayout
        android:id="@+id/relativeMain"
        android:layout_below="@id/btnSearchMainSearch"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <-- MULTIPLE VIEWS HERE -->
      </RelativeLayout>
      <Button
        android:id="@+id/btnSearchMainSearchLow"
        android:text="@string/btnSearchMainSearch_text"
        android:textSize="20sp"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@@id/relativeMain"
        android:width="200dp" 
      /> 
  </RelativeLayout>
  </ScrollView> 
</RelativeLayout>


This how your image should look if you want no extra spacing.

9patch drawable as RelativeLayout background issue

Have a look at android documentation on Nine Patch ; especially be careful about strechable area and padding box. The image defines itself the padding using data pixels given on right and top edges.

Nine Patch is all about logic and graphical programing, which can be very confusing at the beginning...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜