Hey I am trying to create a header with an image in the center and a button at the right corner.
I found this post how to make headers in android with text and buttons like in iOS, and the following tutorial http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/ , and I was able to put the image in the center and set the background. However, no matter what I do my button won’t show up at the right corner.
I tried to see if it was masked by the background or maybe out of the screen, but I could not find the reason for my problem.
my XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/Header"
android:src="@drawable/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff000000"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"/>
<Button
android:id="@+id/lockButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5.0dip"
android:text="TEST"
/>
</LinearLayout>
Why not
relativeYou can put it in center by using
android:layout_centerInParentlike this.Or use
alignParentRightto put it at rightEdited :
This one is for using two imageview in one xml