2012-03-14 74 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