Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android:Textview with vertical scrolling text [duplicate]

Tags:

I am finding a tough time setting the textview with vertical scrolling text. In my dialog I have a textview with large text, since dialog is small window I want the textview text to scroll the vertically so that dialog looks good. Below is my xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="#FFFFFF" >      <ImageView         android:id="@+id/fbcancel"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentRight="true"         android:layout_alignParentTop="true"         android:src="@drawable/fbcancel" />      <EditText         android:id="@+id/fbedittext"         android:layout_width="230dp"         android:layout_height="wrap_content"         android:layout_alignParentLeft="true"         android:layout_below="@+id/imageView1"         android:layout_marginLeft="5dp"         android:layout_marginTop="33dp"         android:background="@drawable/roundcorners"         android:ems="10"         android:gravity="center"         android:hint="@string/fbhint"         android:lines="6"         android:paddingRight="5dp"         android:scrollHorizontally="true" />     <RelativeLayout         android:id="@+id/relativeLayout1"         android:layout_width="80dp"         android:layout_height="250dp"         android:layout_alignParentRight="true"         android:layout_toRightOf="@+id/fbedittext" >          <Spinner             android:id="@+id/spinner"             android:layout_width="50dp"             android:layout_height="30dp"             android:layout_alignLeft="@+id/fbshare"             android:layout_alignRight="@+id/fbshare"             android:layout_below="@+id/fbshare"             android:layout_marginTop="16dp"             android:drawSelectorOnTop="true"             android:entries="@array/fblist"               android:visibility="gone"/>          <ImageView             android:id="@+id/fbpeople"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignLeft="@+id/fbshare"             android:layout_alignRight="@+id/fbshare"             android:layout_below="@+id/fbshare"             android:layout_marginTop="16dp"             android:background="@drawable/people"             android:drawSelectorOnTop="true" />          <ImageView             android:id="@+id/fbshare"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignParentTop="true"             android:layout_centerHorizontal="true"             android:layout_marginTop="65dp"             android:src="@drawable/newfb" />     </RelativeLayout>    <ScrollView android:id="@+id/textAreaScroller"      android:layout_width="fill_parent"          android:layout_height="173px"          android:layout_x="0px"          android:layout_y="25px"       <TextView         android:id="@+id/textView1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignLeft="@+id/fbedittext"         android:layout_alignParentRight="true"         android:layout_below="@+id/fbedittext"         android:layout_marginTop="22dp"         android:lines="7"         android:scrollbars="vertical"         android:text="@string/fbtext" /> </ScrollView>      <ImageView         android:id="@+id/imageView1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignBottom="@+id/fbcancel"         android:layout_alignParentLeft="true"         android:layout_alignParentTop="true"         android:paddingRight="2dp"         android:src="@drawable/askabud" />  </RelativeLayout> 

I tried placing the scroll view but the textview is going in wrong position. Any help is appreciated.

like image 725
hari86 Avatar asked Jan 21 '13 07:01

hari86


1 Answers

1. Via XML

<ScrollView android:id="@+id/textAreaScroller"      android:layout_width="fill_parent"      android:layout_height="173px"      android:layout_x="0px"      android:layout_y="25px"      android:scrollbars="vertical"> <TextView     android:id="@+id/textView1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignLeft="@+id/fbedittext"     android:layout_alignParentRight="true"     android:layout_below="@+id/fbedittext"     android:layout_marginTop="22dp"     android:lines="7"             android:text="@string/fbtext" /> </ScrollView> 

2.Via Code

ScrollView scroller = new ScrollView(this); TextView tv=(TextView)findViewById(R.id.textView1); scroller.addView(tv); 

OR

Putting following properties inside your <TextView>

android:scrollbars = "vertical" 

In the Code

tv.setMovementMethod(new ScrollingMovementMethod()); 
like image 128
Vikalp Patel Avatar answered Oct 04 '22 14:10

Vikalp Patel