2010-07-29 84 views
1

我为我的Android应用程序创建了自定义标题栏。除了我在标题栏上放置了一个复选框,并且我希望我的复选框位于更远的左侧(所以我可以将它与每个列表项中的复选框对齐)之外,所有内容都很好。我无法弄清楚如何将它向左移动。就像它让我说的那样。这里是我的意思,以及我的标题栏XML截图:自定义标题栏定位

http://i28.tinypic.com/2dpfn9.png

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    style="?android:attr/windowTitleBackgroundStyle" 
    android:layout_height="?android:attr/windowTitleSize" 
    > 
    <CheckBox 
    android:id="@+id/inbox_selectall" 
    android:text="" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left|center_vertical" 
    android:focusable="false" 
    android:background="@drawable/checkbox_background" 
    android:button="@drawable/checkbox" 
/> 
<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerVertical="true"> 
    <TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    style="?android:attr/windowTitleStyle" 
    android:id="@+id/inbox_title" 
    android:text="@string/title_inbox" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical|center_horizontal" 
    android:background="@null" 
     android:fadingEdge="horizontal" 
     android:scrollHorizontally="true" 
/> 
</LinearLayout> 
</RelativeLayout> 

回答

1

有一点要注意的是,当你设置android:background到9补丁,你承担其填充。对于title bar graphic,有几个左填充像素(请参见底部的一行像素)。我不记得我的头顶,但你可以使用android:padding覆盖它。

+0

事实上,问题是9补丁填充,你可以写的区域不会走到左边,有几个像素。有点发现。 – Sephy 2010-07-30 17:26:11