Skip to content Skip to sidebar Skip to footer

Textview Size And Scrolling Issue (android)

I just have a TextView in a ScrollView which can contain different text. The size of the text is always different too. The problem is that on different screens this TextView can be

Solution 1:

There is no need of ScrollView you need to add 2 attributes in xml android:maxLines and android:scrollbars="vertical"

XML

<TextViewandroid:id="@+id/babySitterDescTxtView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="18dp"android:maxLines="3"android:paddingLeft="50dp"android:paddingRight="50dp"android:scrollbars="vertical"android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s."android:textColor="@color/fragment_page_txt_color"android:typeface="sans" />

in JAVA

babySitterDescTxtView = (TextView) findViewById(R.id.babySitterDescTxtView);
babySitterDescTxtView.setMovementMethod(newScrollingMovementMethod());

Solution 2:

TextView can scroll the text itself. You don't need to use ScrollView:

<TextView 
    android:text="Some text..." 
    android:id="@+id/my_textview_id" 
    android:textSize="20sp"
    android:textColor="#FFF"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:gravity="center"  
    android:scrollbars="vertical">

Solution 3:

Try this way,hope this will help you to solve your problem.

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="10dp"android:gravity="center"><ScrollViewandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"><TextViewandroid:id="@+id/textview"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:textSize="36sp"android:layout_gravity="center"android:textStyle="bold" /></ScrollView><Buttonandroid:id="@+id/llbuttons"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:text="Button"/></LinearLayout>

Post a Comment for "Textview Size And Scrolling Issue (android)"