Horizontal Scroll View, Scrolling Issue Android

903 views Asked by At

I am new to android programming. I am implementing a simple calculator and I am facing issues with horizontal scroll View. I am using an edit text within Horizontal scroll view. It works completely fine for the first time but as soon as I clear the screen it retains it scrolling limit, meaning that even though there are few digits on the screen I am able to scroll more than it. What I want to achieve is to limit its scrolling. Below are the screen shots and XML code.

First Time

[Second Time][2]

It is still scroll-able even though there are few digits

 <HorizontalScrollView
        android:id="@+id/hsvMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:scrollbars="none"
     >

        <EditText

            android:id="@+id/mainEditText"
            android:paddingTop="10dp"
            android:paddingRight="2dp"
            android:background="#ffff"
            android:ellipsize="end"
            android:focusable="false"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="55sp"

            android:textStyle="bold"

             />

    </HorizontalScrollView>
1

There are 1 answers

2
Bradley Wilson On BEST ANSWER

Try changing round the layout height/width attributes, make HorizontalScrollView layout_width="fill_parent" and EditText layout_width="wrap_content" and layout_height="wrap_content"

<HorizontalScrollView
        android:id="@+id/hsvMain"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:scrollbars="none">

        <EditText
            android:id="@+id/mainEditText"
            android:paddingTop="10dp"
            android:paddingRight="2dp"
            android:background="#ffff"
            android:ellipsize="end"
            android:focusable="false"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="55sp"
            android:textStyle="bold"/>

</HorizontalScrollView>

Edit:

The reason why is wasn't working before because you were telling the scrollview to wrap the content regardless the size of the EditText, so it would only scroll around the EditText. But if you tell the ScrollView to match_parent, it'll always be the width of the screen and then the EditText can be scroll within the parent (ScrollView) regardless of the size.

Note: use match_parent instead of fill_parent, fill_parent is now deprecated. (Although still works)