自定义标题栏定位

时间:2010-07-29 17:02:21

标签: android layout checkbox position titlebar

我为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 个答案:

答案 0 :(得分:1)

需要注意的一点是,当您将android:background设置为9补丁时,您会假设其填充。对于title bar graphic,左边填充有几个像素(请参见底部的像素行)。我不记得我的头脑,但您可以使用android:padding覆盖它。