I've a HorizontalScrollView with a TextSwitcher as child, as shown below.
<HorizontalScrollView
android:id="@+id/horizontal_scroll_view_equation"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:fillViewport="true"
android:layout_gravity="right">
<TextSwitcher
android:id="@+id/text_switcher_equation"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:layout_marginRight="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_medium"
android:id="@+id/text_view_equation_default"
android:background="@android:color/transparent"
android:gravity="center_vertical|right"
android:maxLines="1"
android:textSize="@dimen/font_xxxlarge"
android:scrollHorizontally="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_marginRight="@dimen/spacing_medium"
android:layout_marginLeft="@dimen/spacing_medium"
android:id="@+id/text_view_equation_anim"
android:background="@android:color/transparent"
android:gravity="center_vertical|right"
android:maxLines="1"
android:textSize="@dimen/font_xxxlarge"
android:scrollHorizontally="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TextSwitcher>
</HorizontalScrollView>
The goal of the piece of code above is to create a horizontal scrollable TextView. This code is part of a calculator, so the text of the TextView is dynamic. This means that sometimes the TextView needs to be scrollable, and sometimes not (depending on the length of the text).
The strange behavior that I have now is the following. Once the user enters more and more characters, the TextView becomes perfectly scrollable. However, when the user clears the equation, the HorizontalScrollView keeps collapsed, meaning that it is still scrollable, while the text of the TextView is just one character (a zero). This means that the user can scroll the text to the left and right, while the text is just one character.
In the following, this behavior is demonstrated (see the images below). In the left image, an equation is entered by the user. Then, the user clicks on clear and the equation is cleared, which means that is set to 0. However, as you can see on the right image, the TextView can still be scrolled to the right.
Another remarkable phenomena is that when the user clicks on clear again (so twice in a row), the scrolling of the TextView is not possible anymore. For some reason this is not the case when the user clicks on reset the very first time, but I do not see why.
What I would like to achieve is that once the text of the TextView is cleared (thus the text of the TextView contains one character), that it is not possible for the user to scroll the text to the left or right.