Android -- Title bar invisible padding
So, I've seen several instances of padding being a problem in a custom title bar but this seems to be unique and I would love to see if anyone could s开发者_如何学JAVAhed some light on it.
Here's what I have:
There's padding to the right of the configure button that shouldn't be. I want a little bit of padding in the end but, to prove a point, this is with no padding set. Here's the layout for the custom title bar.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="8dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="@drawable/icon" />
<TextView android:id="@+id/customtitlebar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="COMPANY"
android:textSize="20dip"
android:textColor="#205cc7"
android:textStyle="bold"
android:paddingTop="15px" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="@drawable/configure" />
</LinearLayout>
</RelativeLayout>
I thought maybe the layout I gave a dummy id "container" was being cut off as well and the problem was outside this layout, but, when I change its background to red, it takes up the whole screen.
Does anyone have a solution short of hiding the OS title bar and making it a header for every screen layout?
Try to set android:layout_alignParentRight="true" to the LinearLayout which should be strechted to the right edge of the RelativeLayout.
Apart from that I agree to Octavian Damiean that your definition is to complex to receive the layout you want.
This layout has the same problem that the first image does. It uses alignParentRight and simplifies the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF" >
<ImageView
android:id="@+id/titleImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="8dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="@drawable/icon" />
<TextView android:id="@+id/customtitlebar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="55dip"
android:text="COMPANY"
android:textSize="20dip"
android:textColor="#205cc7"
android:textStyle="bold"
android:paddingTop="15px" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:src="@drawable/configure" />
</RelativeLayout>
精彩评论