2012-03-14 92 views
0

我想在android 2.2中實現類似於操作欄的東西。 這是我的main.xml線性佈局不可見/重疊

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<include 
    android:id="@+id/header" 
    layout="@layout/header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 
<ScrollView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 

> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@drawable/dark_button" 
    > 

     <Button 
      android:id="@+id/brand_id" 
      android:layout_width="fill_parent" 
      android:layout_height="80dip" 
      android:text="@string/brand_label" 
      android:textColor="@color/white" 
      android:background="@drawable/dark_button" 
     /> 
     <Button 
      android:id="@+id/car_id" 
      android:layout_width="fill_parent" 
      android:layout_height="80dip" 
      android:text="@string/car_label" 
      android:textColor="@color/white" 
      android:background="@drawable/dark_button" 
      android:visibility="gone" 
     /> 
     <Button 
      android:id="@+id/model_id" 
      android:layout_width="fill_parent" 
      android:layout_height="80dip" 
      android:text="@string/model_label" 
      android:textColor="@color/white" 
      android:background="@drawable/dark_button" 
      android:visibility="gone" 
     /> 
     <Button 
      android:id="@+id/location_id" 
      android:layout_width="fill_parent" 
      android:layout_height="80dip" 
      android:text="@string/location_label" 
      android:textColor="@color/white" 
      android:background="@drawable/dark_button" 
      android:visibility="gone" 
     /> 

     <Button 
      android:id="@+id/submit" 
      android:layout_width="fill_parent" 
      android:layout_height="80dip" 
      android:text="@string/submit_label" 
      android:textColor="@color/white"  
      android:layout_marginTop="10dip" 
      android:background="@drawable/dark_button" 
      android:visibility="gone" 
     /> 
     <ProgressBar 
      android:id="@+id/mainProgressBar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:visibility="gone" 
     /> 

    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

這是我header.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_weight="1" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/logo_toyota" 
    android:layout_weight="1" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"   
    android:text="Button" 
    android:layout_weight="1" /> 

</LinearLayout> 

我得到我想知道什麼是錯的代碼的O/P爲ScreenShot, Only header is visible

。我是android開發新手。任何幫助,高度讚賞。

在此先感謝 祖阿曼高塔姆

+3

你忘記解釋你的問題了嗎? – waqaslam 2012-03-14 14:29:31

+0

Ohh對不起!我認爲我必須詳細闡述。只有包含的部分可以在main.xml中看到。並且應該有一個按鈕可見。我不知道什麼是錯的。 – 2012-03-14 14:43:28

回答

2

它在水平方向顯示,因爲它是默認

設置在main.xml中

的根佈局只是把機器人:方向= 「垂直」

+0

非常感謝Anand。它的工作:) – 2012-03-14 14:48:03

2

而不是推出自己的代碼,我強烈推薦這個開源項目,(https://github.com/johannilsson/android-actionbar),我用它在我自己的項目中,它對我來說工作得很好。

+0

好主意推薦一個圖書館。我會建議看看ActionBarSherlock,而不是:http://actionbarsherlock.com/ – elevine 2012-03-14 14:55:27

+0

我知道這個項目,但從來沒有嘗試過,它是否像它聲稱的那麼好?我推薦的庫非常易於使用,另一方面,ActionBarSherlock使用與ICS提供的API相同的API(但包名不同),_and_提供了更好的功能。所以我認爲兩者都有它們的優點,所以你們一定要研究並決定哪種最適合你的需求。 – Kai 2012-03-14 15:03:18

+2

我已經使用了ActionBarSherlock,它不辜負它的主張。它一般被Android開發人員高度重視。其中一個最好的特性就是它只是向ActionBar提供向後兼容性,所以在Android 3.0和更高版本的設備上,ABS會讓本地API接管。 – elevine 2012-03-14 15:14:34