9patch drawable作为RelativeLayout背景问题

时间:2011-05-13 16:28:17

标签: android android-layout

我在Activity中有RelativeLayout作为标题,我希望它有9.png drawable作为背景。 这是可绘制的:

enter image description here

我收到的内容:

enter image description here

如您所见 - 有额外的间距。

这里我使用RGB颜色作为背景(以及我希望它看起来如何使用9patch):

enter image description here

我做了一些有趣的事情,或者9patch看起来像这样是正常的吗?

更新代码

<?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>

1 个答案:

答案 0 :(得分:2)

如果您不想要额外的间距,请查看图像的外观。

image.9.png

查看Nine Patch上的Android文档;关于可拉伸区域和填充盒特别要小心。图像使用右边和上边缘给出的数据像素定义填充。

Nine Patch完全是关于逻辑和图形编程的,一开始可能会让人很困惑......

相关问题