• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to create a TextView of set size with scroll bars when needed?

Hello, I want to create a TextView of a set size inside a horizontal linear layout, that is scrollable when the content gets too long for the TextView to properly display. Here's the XML structure I am currently using:
Code:
    <LinearLayout
        android:id="@+id/item_bottom
 
        android:layout_width="match_parent"


        android:layout_height="match_parent"


        android:orientation="horizontal"


        android:weightSum="8">





        <HorizontalScrollView


            android:layout_width="0dp"


            android:layout_height="match_parent"


            android:layout_weight="5"





            android:clipToPadding="true"


            android:fadeScrollbars="true"


            android:scrollbarStyle="insideOverlay"


            android:scrollbars="horizontal">





            <TextView


                android:id="@+id/item_balance"


                android:layout_width="wrap_content"


                android:layout_height="match_parent"


                android:fontFamily="sans-serif-black"


                android:singleLine="true"


                android:text="26677889.44 €"


                android:textColor="@android:color/black"


                android:textSize="36sp"


                android:textStyle="bold" />


        </HorizontalScrollView>





        <HorizontalScrollView


            android:layout_width="0dp"


            android:layout_height="match_parent"


            android:layout_weight="3"





            android:clipToPadding="true"


            android:fadeScrollbars="true"


            android:scrollbarStyle="insideOverlay"


            android:scrollbars="horizontal">





            <TextView


                android:id="@+id/item_payment"


                android:layout_width="wrap_content"


                android:layout_height="match_parent"


                android:background="@color/lightred"


                android:gravity="bottom|end"


                android:singleLine="true"


                android:text="22222"


                android:textColor="@android:color/black"


                android:textSize="24sp" />


        </HorizontalScrollView>





    </LinearLayout>
This however leads to the TextView elements inside the HorizontalScrollView elements to have their width be set to wrap_content. Manually changing this to match_parent or adding android:fillViewport="true" to the HorizontalScrollView elements did, unlike with normal ScrollView elements, not help.

This is what it looks like in the design view:
androidstudio.jpg


The HorizontalScrollView elements already have the correct size, the only issue is that the TextView elements inside of them do not allow their width to be set to match_parent. Is there something I missed?
 
I have found a solution for my specific problem. Instead of using a TextView object inside a HorizontalSrollView object to allow me to scroll the TextView sideways, I'm using an EditText object with all of its additional properties removed, save for its scrolling feature:
Code:
<LinearLayout
            android:id="@+id/item_bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="8">

            <EditText
                android:id="@+id/item_balance"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:background="@android:color/transparent"
                android:clickable="false"
                android:cursorVisible="false"
                android:focusable="false"
                android:fontFamily="sans-serif-black"
                android:singleLine="true"
                android:text="26677889.44 €"
                android:textColor="@android:color/black"
                android:textSize="36sp"
                android:textStyle="bold" />
 
Back
Top Bottom