Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll View not showing all the views in android

I am unable to see the top most views under ScrollView. I had placed the scrollview under Relative layout. ScrollView has a child layout i.e. Linear layout which has some series of buttons. Problem is that i am unable to see the top most views which are present in the ScrollView.

Below is the layout xml code.

<?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:background="#217d27"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:onClick="backPressed"
            android:text="Back"
            android:textColor="#000" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="Heading Text"
            android:textColor="#fff"
            android:textSize="20sp" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:onClick="homeButtonClicked"
            android:text="Home"
            android:textColor="#000" />
    </RelativeLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#fff"
            android:orientation="vertical" >

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Button 1"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 2"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 3"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 4"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 5"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 6"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 7"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 8"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 9"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 10"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 11"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 12"
                android:textColor="@color/black" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

Please see the screen shot for reference.

Screen shot

like image 387
ravi Avatar asked Nov 29 '22 07:11

ravi


2 Answers

just remove this line in linear layout which is direct child of scroll view android:layout_gravity="center" try this code which is updated

<?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:background="#217d27"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:onClick="backPressed"
            android:text="Back"
            android:textColor="#000" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="Heading Text"
            android:textColor="#fff"
            android:textSize="20sp" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:onClick="homeButtonClicked"
            android:text="Home"
            android:textColor="#000" />
    </RelativeLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#fff"
            android:orientation="vertical" >

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Button 1"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 2"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 3"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 4"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 5"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 6"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 7"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 8"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 9"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 10"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 11"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 12"
                android:textColor="@color/black" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>
like image 149
Bhanu Sharma Avatar answered Dec 04 '22 14:12

Bhanu Sharma


Just change the LinearLayout inside the ScrollView

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center"
        android:background="#fff"
        android:orientation="vertical" >

Give the android:layout_gravity="top|center" instead of android:layout_gravity="center"

Hope it helps.

like image 30
AnujMathur_07 Avatar answered Dec 04 '22 14:12

AnujMathur_07