Prem
Prem

Reputation: 1684

Need help in Dashboard in Android

I have created dashboard for my app. In that I added search button also. I wish to align this button to right side but for that i don't want to use the margin. I have added the image of my layout + code.

UPDATED

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >
    <RelativeLayout style="@style/TitleBar" >

    <ImageView
        android:id="@+id/logo"
        style="@style/TitleBarLogo"
        android:layout_toRightOf="@id/titlebar"
        android:contentDescription="Logo"
        android:src="@drawable/logo" />

    <ImageView
        style="@style/TitleBarSeparator"
        android:layout_toRightOf="@id/logo"
        android:visibility="visible" />

    <ImageButton
        style="@style/TitleBarAction"
        android:layout_alignParentRight="true"
        android:contentDescription="Searching..."
        android:onClick="onClickSearch"
        android:src="@drawable/title_search" />
</RelativeLayout>
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/titlebar"
        android:layout_weight="1"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dip"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/home_btn_feature1"
                style="@style/HomeButton"
                android:drawableTop="@drawable/home_button1"/>

            <Button
                android:id="@+id/home_btn_feature2"
                style="@style/HomeButton"
                android:drawableTop="@drawable/home_button2"                    
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dip"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/home_btn_feature3"
                style="@style/HomeButton"
                android:drawableTop="@drawable/home_button3"/>

            <Button
                android:id="@+id/home_btn_feature4"
                style="@style/HomeButton"
                android:drawableTop="@drawable/home_button4"/>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

UPDATED

styles.xml

<style name="TitleBar">
        <item name="android:id">@id/titlebar</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:orientation">horizontal</item>
        <item name="android:background">@color/title_background</item>
    </style>

    <style name="TitleBarLogo">
        <item name="android:id">@id/title_logo</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:clickable">true</item>
    </style>

    <style name="TitleBarAction">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:background">@drawable/title_button</item>
    </style>
<style name="TitleBarSeparator">
        <item name="android:layout_width">1px</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:background">@color/title_separator</item>
    </style>

OLD

NEW UPDATED

UPDATED MY CODE AND JUST ONE STEP TO COMPLETE IT. THE SEPERATOR IS SOME HOW NOT VISIBLE.

If anyone has any idea please kindly help me.

Thank you

Upvotes: 1

Views: 488

Answers (2)

TryTryAgain
TryTryAgain

Reputation: 7820

Although I would recommend looking into using the Action Bar if at all possible,

android:layout_alignParentRight="true"

should work, you could also acheive what you want by making you TitleBarLogo and magnifying glass graphic a 9-patch image that leaves the middle blank and resizes automatically without distorting the graphic.

Upvotes: 1

Vyacheslav Shylkin
Vyacheslav Shylkin

Reputation: 9791

Try

<ImageButton
        style="@style/TitleBarAction"
        android:contentDescription="Searching..."
        android:onClick="onClickSearch"
        android:layout_alignParentRight="true"
        android:src="@drawable/title_search" />

Upvotes: 2

Related Questions