2012-03-28 83 views
1

在开发Android应用程序时,我偶然发现了一个令人困惑的问题。我正在创建的UI元素是一个具有自定义搜索字段的标题栏。在Android UI编辑器中,一切看起来都很棒,但第二个我使用模拟器或其设备,并压缩放大镜图像并剪辑编辑文本。我已经尝试了许多事情,包括将搜索区域的背景图像更改为当前位于父LinearLayout中的自定义搜索字段。但是,这会导致搜索字段大小失控。Android UI编辑器/显示器问题

欢迎任何建议。

我的问题是:
1)如何解决这个问题,同时保持搜索区域的外观?
2)为什么会发生此问题?

证实,对以下设备:
三星GALAXY Nexus 4.0.2
摩托罗拉变焦4.0.3
歌Nexus S 2.3.7

这是UI编辑器的截图:
This is a screenshot of the UI editor

这是它在所有测试设备上看起来像的屏幕截图:
This is a screenshot of what it looks like on all devices tested

用来产生这些UI元素的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/header" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/title_bar_matte" 
android:gravity="center_vertical" 
android:orientation="horizontal" > 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_margin="10dp" 
    android:layout_weight="1.0" 
    android:background="@drawable/search_field" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="15dp" 
     android:src="@drawable/magnifying_glass" /> 


    <EditText 
     android:id="@+id/campus_map_acitivity_search" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="10dp" 
     android:layout_weight="1.0" 
     android:background="#0FFF" 
     android:hint="Search" 
     android:imeOptions="actionSearch" 
     android:singleLine="true" /> 
</LinearLayout> 

<Button 
    android:id="@+id/campus_map_activity_goto_list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    android:background="@drawable/button_list" /> 

<Button 
    android:id="@+id/campus_map_activity_my_location" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:background="@drawable/button_location" /> 

</LinearLayout> 

回答

2

只是想出了这个问题。搜索背景图像的顶部和左侧设置为9贴片比例。这一切都很好,但我们忘记了设置底部和右侧填充区域,以便内容可以存在。

http://radleymarx.com/blog/simple-guide-to-9-patch/

记得设置填充的区域!

事实证明,Android UI编辑器不能处理像设备这样的9-patch图像。这对我来说似乎是一个错误。