Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have designed horizontalscrollview for listview i have more than 5 column in list view. i have problem in horizontalscrollview. it scrolls 1 time only at second time i can't scroll. text hided. please give me solution for that.

What I have tried:

<?xml version="1.0" encoding="utf-8"?>

<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hscroll"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:layout_gravity="center_horizontal"
    tools:context=".ReportFragment"
   >




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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp">


            <TextView
                android:id="@+id/date"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Date"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1"
                />

            <TextView
                android:id="@+id/empname"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Employee"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1"
                />

            <TextView
                android:id="@+id/intime"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Time"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/outtime"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Out Time"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/hours"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Hours"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/inaddress"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Address"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1" />
            <TextView
                android:id="@+id/inaddress1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Address1"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1" />
            <TextView
                android:id="@+id/inaddress2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Address2"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_weight="1" />


        </LinearLayout>



        <ListView
            android:id="@+id/lvMonthlyAttend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="50dp">

        </ListView>

    </LinearLayout>


</HorizontalScrollView>
Posted
Updated 9-Sep-19 11:01am
Comments
David Crow 9-Sep-19 10:43am    
"...at second time i can't scroll. "

What exactly does this mean? Is the UI frozen? Is it still scrolled all the way to the right from the first time?

I put your layout as-is in a dummy app and it ran fine on an emulator. So the problem may be elsewhere.

1 solution

I believe that your issue is that you are, by specifying a width of 0dp and a weight of 1 for TextViews (other than the first 2), telling the views to fit in the width of the linear layout they are contained within.

The fix is to specify widths that will force the data to extend beyond the width of the linear layout and thus there is scrollable data (i.e. data that extends beyond the visible limit). Weight then becomes superfluous (ignored if left in) so lines with weight have been removed.

e.g. the following layout (tested on a tablet) is scrollable. :-

<?xml version="1.0" encoding="utf-8"?>

<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hscroll"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:layout_gravity="center_horizontal"
    >



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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp">


            <TextView
                android:id="@+id/date"
                android:layout_width="255dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Date"
                android:textColor="@color/black"
                android:textSize="15dp"
                />

            <TextView
                android:id="@+id/empname"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Employee"
                android:textColor="@color/black"
                android:textSize="15dp"
                />

            <TextView
                android:id="@+id/intime"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Time"
                android:textColor="@color/black"
                android:textSize="15dp"
                />

            <TextView
                android:id="@+id/outtime"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Out Time"
                android:textColor="@color/black"
                android:textSize="15dp"
                />

            <TextView
                android:id="@+id/hours"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Hours"
                android:textColor="@color/black"
                android:textSize="15dp"
                />

            <TextView
                android:id="@+id/inaddress"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Address"
                android:textColor="@color/black"
                android:textSize="15dp"
                />
            <TextView
                android:id="@+id/inaddress1"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Address1"
                android:textColor="@color/black"
                android:textSize="15dp"
                />
            <TextView
                android:id="@+id/inaddress2"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="In Address2"
                android:textColor="@color/black"
                android:textSize="15dp"
                />


        </LinearLayout>



        <ListView
            android:id="@+id/lvMonthlyAttend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="50dp">

        </ListView>

    </LinearLayout>


</HorizontalScrollView>


Obviously you would need to adopt suitable widths.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900