2011-08-31 69 views
0

我想用下面的代碼插入一個標題欄。我儘量保持最左邊和最右邊的兩個按鈕。但是這些按鈕在標題欄上不可見。
的TextView作爲這裏的標題欄,那就是:爲按鈕使用標題欄時遇到問題?

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

代碼:

<

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> 

廣東話guess.Can任何一個可以幫助我

謝謝提前

+0

沒有 「下面的代碼」 在你的問題。 – Ronnie

+0

radha

+0

和對於按鈕的代碼是: – radha

回答

0

您應該像這樣定義一個佈局並將其設置爲標題欄。

<?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> 
+0

感謝您的代碼。但是,當我嘗試添加顏色到標題欄中的代碼,你已經建議並使其fill_parent。它不起作用 – radha

+0

當我使用textview作爲標題欄時,textview應該是fill_parent,我希望在其上放置按鈕。 – radha

+0

你想要文本在按鈕下面? – Ronnie

0

什麼類型家長做這些項目在哪裏?就個人而言,我可能會使用TableLayout,然後使用重力來定位我希望它們出現的對象。使用重量標籤爲標題欄上的對象設置間距。

+0

上午使用填充父項textview,我希望按鈕在textview上。 – radha

0

使用這個,告訴我這是爲你工作嗎?

<?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> 
+0

Ya。我需要上層,即帶有從左到右填充顏色的文本視圖和按鈕。當試圖這不工作。 – radha

+0

我真的不能讓你很好..但你可以設置顏色到整個佈局.. – MKJParekh

0
<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">