2012-10-17 138 views
1

我遇到了9patch映像的问题。布局设置为50dp并带有9patch背景,但在小屏幕上加载时,布局大于50dp。9补丁缩小问题

但是我有另一个具有相同的9patch背景(menuBtn)的布局,并没有扩大,所以我不知道是什么使9patch在这一个布局上行事不端。

SS:
enter image description here

<?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="50dp" 
    android:padding="0dp" 
    android:background="@drawable/actionbar"> 
    <RelativeLayout 
     android:id="@+id/menuBtn" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:background="@drawable/actionbar" 
     android:clickable="true"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:src="@drawable/actionbar_menu"/> 
    </RelativeLayout> 
    <ImageView 
     android:id="@+id/div1" 
     android:layout_width="1px" 
     android:layout_height="50dp" 
     android:layout_toRightOf="@id/menuBtn" 
     android:src="@drawable/actionbar_divider"/> 
</RelativeLayout> 

9patch IMG:
enter image description here

回答

3

想通了,这是一个奇怪的错误?无论如何,9patch在小屏幕尺寸上高于50dp,所以基本背景设置为操作栏时,它不会缩放。

但是,如果我在主RelativeLayout内部嵌套另一个RelativeLayout并将该背景设置为操作栏,则它可以很好地缩放。不知道为什么原始的RelativeLayout没有。

例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:padding="0dp"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:padding="0dp" 
     android:background="@drawable/actionbar"> 
    </RelativeLayout> 
</RelativeLayout> 

此代码的工作,所以是...