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.
[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>
Try changing round the layout height/width attributes, make
HorizontalScrollViewlayout_width="fill_parent"andEditTextlayout_width="wrap_content"andlayout_height="wrap_content"Edit:
The reason why is wasn't working before because you were telling the
scrollviewto wrap the content regardless the size of theEditText, so it would only scroll around theEditText. But if you tell theScrollViewtomatch_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_parentinstead offill_parent,fill_parentis now deprecated. (Although still works)