Gödel77
Gödel77

Reputation: 839

First embedded ImageView in ScrollView not shown

I have a ScrollView with a LinearLayout and inside 4 ImageView's but the first one is not shown.

(The names of drawables and id's are NOT the same, I wrote XXX intentionally)

This is my layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linLayoutAbout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical" >


    // Another stuff
    ...  
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="5dp"
        android:orientation="vertical" >

        <ScrollView   
            android:id="@+id/scrollView1"
            android:layout_width="wrap_content"
            android:layout_height="65dp"
            android:layout_gravity="center"
            android:isScrollContainer="true" >  
            <LinearLayout
                android:id="@+id/linLayoutScrollView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="vertical" >    

                <ImageView             //<- Just this ImageView is not shown
                    android:id="@+id/logo_XXX"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginBottom="5dp"
                    android:src="@drawable/logo_XXX" />

                <ImageView
                        android:id="@+id/logo_XXX"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginBottom="5dp"
                        android:src="@drawable/logo_XXX" />

                <ImageView
                    android:id="@+id/logo_XXX"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginBottom="5dp"
                    android:src="@drawable/logo_XXX" />

                <ImageView
                    android:id="@+id/logo_XXX"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/logo_XXX" />
            </LinearLayout>                                          
        </ScrollView>
    </LinearLayout> 


    <Button
        android:id="@+id/close_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="@string/close_about" />

If I set android:layout_height with some dp_value then I can't see the first ImageView, but If I set it with "wrap_content", then I can see all ImageView's.

May anyone tell me what I do wrong and how can I solve it?

Thank you in advance.

Upvotes: 0

Views: 920

Answers (2)

Faruk Yazici
Faruk Yazici

Reputation: 2404

You have to delete the line

android:layout_gravity="center"

in the LinearLayout with id "@+id/linLayoutScrollView1" inside the ScrollView. Because it centers the linear layout within those 65 pixels of the ScrollView, which means half of the images above are gone out of the screen.

Try this code;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linLayoutAbout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical" >
    // Another stuff
    ...  


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="5dp"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="wrap_content"
            android:layout_height="65dp"
            android:layout_gravity="center"
            android:isScrollContainer="true" >

            <LinearLayout
                android:id="@+id/linLayoutScrollView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/logo_XXX1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginBottom="5dp"
                    android:src="@drawable/ic_launcher" />

                <ImageView
                    android:id="@+id/logo_XXX2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginBottom="5dp"
                    android:src="@drawable/ic_launcher" />

                <ImageView
                    android:id="@+id/logo_XXX3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginBottom="5dp"
                    android:src="@drawable/ic_launcher" />

                <ImageView
                    android:id="@+id/logo_XXX4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_launcher" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <Button
        android:id="@+id/close_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="close_about" />

</LinearLayout>

I changed that LinearLayout and added some real values to the images. Now all the images show up properly. Just replace with your images and see the difference.

Upvotes: 1

Faruk Yazici
Faruk Yazici

Reputation: 2404

65 must be smaller than the total height. It must show when you try a larger dp value, maybe 150 etc. It worked some random images I tried.

Upvotes: 0

Related Questions