简体   繁体   中英

Linear Layout not visible / Overlapping

I am trying to implement something like an action bar in android 2.2 . This is my 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>

And this is my 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>

I am getting the o/p as ScreenShot,仅标题可见

I am wondering what is wrong with the code. I am new to android development. Any help is highly appreciated.

Thanks in advance Aman Gautam

It is showed in horizontal orientation because it is set by default

In root layout of main.xml

just put android:orientation="vertical"

我极力推荐这个开源项目(https://github.com/johannilsson/android-actionbar),而不是发布自己的代码,我在自己的项目中使用了它,并且对我来说效果很好。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM