2014-01-22 47 views
0

我有一个EditText上,并在相对布局的按钮的作用。下面是XML:机器人:layout_centerVerticle =“真”没有对我的编辑文本

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="5sp" > 

    <Button 
     android:id="@+id/action_home_button" 
     android:layout_width="35sp" 
     android:layout_height="35sp" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:background="@drawable/home_button" /> 

    <EditText 
     android:id="@+id/action_search" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toRightOf="@+id/action_home_button" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:hint="Some hint..." 
     android:textColor="#FFFFFF" 
     android:textColorHint="#DDDDDD" /> 

</RelativeLayout> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="5sp" 
    android:layout_alignParentBottom="true" 
    android:background="#EC9D21" /> 

</RelativeLayout> 

的问题是,该按钮在RelativeLayout就好了中心,但我EditText对齐布局的顶部。有什么我失踪的?先谢谢你。

编辑在上面,我更新了我的XML。我将其设置为我的操作栏的自定义视图。但这应该没有什么不同,因为按钮没有问题对齐垂直居中。感谢名单

编辑的EditText应该对准中心垂直

+1

这些类型的问题,它通常更容易,如果您发布完整的XML。然后我们可以在我们的编辑器中复制/粘贴以查看结果。另外,总有另一个'View'遮蔽事物的可能性。 – codeMagic

+0

在RelativeLayout下面的属性是什么?另外,你可以发布你想要它的样子吗?我认为你有一些不必要的嵌套... – codeMagic

+0

你尝试过'android:layout_gravity'吗? – t0mm13b

回答

0

某些主题中的标准EditText似乎在其周围和/或下面嵌入了paddingmargin。如果你想消除这个问题,那么我会大量建议要么使用nine patch,背景颜色,或自定义背景一些其他形式。

试图设置一个负底部边距或疯狂的东西可能会解决一个标准EditText的问题,但是你必须在Android版本之间小心,因为它们的EditTexts可以有不同的主题并给出相当意想不到的行为。

至于为什么主题的设计师选择了这个缺口的下方是超越我。我最好的猜测是,当开发人员不在垂直对齐的EditText之间添加保证金时,他们是“保存面子”的方式?

0

+1 Uxonith。例如,改变背景似乎有诀窍。 android:background="#000000"。对我来说这工作正常,因为我不得不改变背景,但如果你需要标准的编辑文本,这不会是一个解决方案。

+0

我想我应该留下一个答案的评论,所以我只是添加一个,如果你决定要接受它:) – Uxonith