开发者

Facing problem while using Title bar?

I am trying to insert a title bar with the following code. I try to keep the two buttons on it at left most and right most ends. But the buttons are not visible on the titlebar.

TextView is used as a title bar here and that is :

<TextView
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="CAMERA"
android:gravity="center_horizontal"
android:background="#4C7D7E"
>
</TextView>

code for buttons:

<

Button
android:id="@+id/save"
android:layout_width="144px"
android:layout_height="37px"
android:text="save"
android:layout_x="7px"
android:layout_y="388px"
>
</Button>
<Button
android:id="@+id/send"
android:layout_width="144px"
android:layout_height="37px"
android:text="send"

android:layout_x="158px"
android:layout_y="388px"
>
</Button>

Cant guess.Can any one help me

Thanks in 开发者_Python百科advance


You should define a layout like this and set it as title bar.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/titlebar"
        android:layout_width="fill_parent" android:layout_height="80dp"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <Button
         android:id="@+id/save"
         android:layout_width="144px"
         android:layout_height="37px"
         android:text="save"/>

        <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/titleText"
        android:text="right" />

        <Button
        android:id="@+id/send"
        android:layout_width="144px"
        android:layout_height="37px"
        android:text="send"
        android:layout_gravity="right"/>
</LinearLayout>


What type of parent do these items reside in? Personally, I would probably use a TableLayout and then use gravity to position the objects where I wanted them to appear. Use the weight tag to set the spacing for the objects on the titleBar.


Use This and tell me is this work for you?

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout android:id="@+id/titlebar" 
            android:layout_width="fill_parent" android:layout_height="wrap_content" 
            xmlns:android="http://schemas.android.com/apk/res/android" android:weightSum="3"> 
            <Button 
             android:layout_weight="1"
             android:id="@+id/save" 
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content" 
             android:text="save"/> 

            <TextView 
             android:layout_weight="1"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"  
            android:id="@+id/titleText" 
            android:text="right" /> 

            <Button 
             android:layout_weight="1"
            android:id="@+id/send" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="send" 
            android:layout_gravity="right"/> 
    </LinearLayout> 


<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:background="@drawable/main_bg">

    <RelativeLayout android:id="@+id/Rel_Top"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:background="#4C7D7E">
        <Button android:id="@+id/Btn_Back"
            android:layout_width="wrap_content"android:layout_height="wrap_content"
            android:layout_alignParentLeft="true" android:layout_marginLeft="10dip"
            android:layout_centerVertical="true" android:background="@drawable/settings"/>


        <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/Text_Title"
        android:text="Title"  android:layout_centerInParent="true"
                android:singleLine="true"/>

        <Button android:id="@+id/Btn_Search"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_alignParentRight="true" android:layout_marginRight="10dip"
            android:layout_centerVertical="true" android:background="@drawable/search" />
        </RelativeLayout>
</RelativeLayout>
If you want to change the background color then change the background color in <RelativeLayout android:id="@+id/Rel_Top"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:background="#4C7D7E">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜