0

I need a TextView that has the same functionality as, for example, the EditText that shows the equation/result in the Huawei Calculator, but without the need of a cursor, etc.

In this calculator, the equation starts from the right side. When characters are added to the equation, the characters are added at the right side of the equation. Also, the equation always shows the newest entered characters without the need of scrolling to the right. The following image illustrates this functionality.

As a summary, what I need is the following.

  • The text is aligned to the right side of the screen.
  • The text is horizontally scrollable (if necessary).
  • By default, the newest entered characters are shown, except if the user makes use of the scrollbar.

I've tried a lot. Many examples show a HorizontalScrollView with as child a TextView, as for example in the following link.

Example TextView in HorizontalScrollView

However, when using this approach, the HorizontalScrollView must be programmatically scrolled to the right at every new entered character. In the Huawei Calculator, this is not the case.

In the following, the code is shown what I've so far.

<HorizontalScrollView
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:fillViewport="true"
    android:layout_gravity="right"
    android:scrollbars="none">
    <TextSwitcher
        android:id="@+id/text_switcher_equation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/text_view_equation_one"
            android:maxLines="1"
            android:gravity="right|center"
            android:textColor="@android:color/black"
            app:autoSizeTextType="uniform"
            android:text="testtest"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <TextView
            android:id="@+id/text_view_equation_two"
            android:maxLines="1"
            android:gravity="right|center"
            android:textColor="@android:color/black"
            app:autoSizeTextType="uniform"
            app:autoSizeMinTextSize="30sp"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </TextSwitcher>
</HorizontalScrollView>

The problems that I faced with this code is described in the following link.

How to collapse a HorizontalScrollView when scrolling is not necessary?

Anyone an idea how I can achieve this functionality?

t.r.hogenkamp
  • 73
  • 2
  • 7

0 Answers0