Blank white bar in the layout without reason

时间:2018-12-19 11:36:17

标签: android android-studio android-layout

I have a big blank white bar at the bottom of my layout and i don't know why. It is really anoying and i really don't love it :D Please help me to delete it!

Blank bar My layout code:

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


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ededed">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.design.card.MaterialCardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                app:cardBackgroundColor="@android:color/white"
                app:cardCornerRadius="10dp"
                app:cardElevation="2dp"
                app:cardPreventCornerOverlap="true">

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:background="@drawable/ic_menu_camera" />
            </android.support.design.card.MaterialCardView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/text_style_header"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/heading"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Heading...."
                    android:textAppearance="?attr/textAppearanceHeadline6"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/description_short"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="2dp"
                    android:background="@drawable/text_style_desc"
                    android:text="Desc" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="12dp"
                    android:background="@drawable/text_style_desc"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/description"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginTop="2dp"
                        android:background="@drawable/text_style_desc"
                        android:text="text text text tex" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

In the preview of android studio there is showing nothing, but if i build and run the app it shows the bar. Is this bar from

SOLUTION: This layout was from a ViewPager layout which had a blank space for adding dots. This was the problem.

Thank you all!

2 个答案:

答案 0 :(得分:2)

Try this

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ededed"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.design.card.MaterialCardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            app:cardBackgroundColor="@android:color/white"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp"
            app:cardPreventCornerOverlap="true">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@drawable/dishu" />

        </android.support.design.card.MaterialCardView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:orientation="vertical">

            <TextView
                android:id="@+id/heading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Heading...."
                android:textAppearance="?attr/textAppearanceHeadline6"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/description_short"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:background="@color/colorAccent"
                android:text="Desc" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="12dp"
                android:background="@color/colorPrimaryDark"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/description"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="2dp"
                    android:text="text text text tex" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

答案 1 :(得分:0)

Give background color to the first linear layout instead of scrollview. And add fillViewport = true in scrollview