Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android scrollview hiding top content

I am having trouble using ScrollView. For some strange reason, it is hiding the content to be displayed on the top. I tried giving margin, padding, etc. but nothing seems to work. This is my layout:

    <?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"
    android:orientation="vertical" android:background="@drawable/background">
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="@drawable/titlebar"
        android:id="@+id/titlebar">
        <TextView android:layout_width="fill_parent" android:id="@+id/textView1"
            android:layout_height="fill_parent" android:layout_gravity="center"
            android:gravity="center" android:textColor="@color/white"
            android:textSize="20dip" android:text="Help"></TextView>
    </LinearLayout>
    <ScrollView android:layout_height="wrap_content" android:id="@+id/scrollView1"
        android:layout_width="fill_parent">
        <LinearLayout android:orientation="vertical" android:id="@+id/linearLayout2"
            android:gravity="center" android:layout_width="fill_parent"
            android:layout_gravity="center" android:layout_height="fill_parent"
            android:paddingLeft="10dip" android:paddingRight="5dip">
            <ImageView android:layout_height="wrap_content"
                android:src="@drawable/icon" android:layout_marginTop="10dip"
                android:id="@+id/help_icon" android:layout_width="fill_parent"
                android:layout_marginBottom="15dip"></ImageView>
            <TextView android:layout_height="wrap_content"
                android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi. "
                android:id="@+id/help_text" android:layout_width="wrap_content"
                android:textColor="@color/black" android:textSize="15dip"
                android:paddingBottom="10dip"></TextView>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

My image is getting hidden behind the top titlebar and only a small part of its bottom is visible in the device/emulator. It appears fine in Eclipse. I am using ADT11

Thanks in advance!

like image 884
mvrck Avatar asked Feb 24 '23 22:02

mvrck


1 Answers

Hi I had the same problem, and after investigation I have found the solution, and in your XML code I can see that you are doing the same mistake in layout.

The problem is that you are setting the ScrollView child (LinearLayout) layout_gravity to center. Remove this line and it should work for you.

android:layout_gravity="center"   //remove this 
like image 150
user3098756 Avatar answered Mar 07 '23 07:03

user3098756