0

I know that this is a very debated topic on this website and it has been asked many times before. But all the responses so far haven't been very helpful.

Essentially what i am trying to do, is create a textField, that contains information. Like a console in counter Strike for example. And i want to have a text entry box that allows for user entry. I would Like to be able to dynamically add lines of text to the above mentioned textbox, and i want it to scroll the the bottom. So the latest text entry or added text is always at the bottom. But i can still scroll up and go through the old entries.

So essentially exactly like the counter Strike console. Or any other game text consoles:

http://www.counter-strike-source-tips.com/images/counter-strike-source-binding.jpg

Here is an image as an example ^^

Thank you so much. I've spent 2 days on this...

Here is what i have tried so far:

Scroll View Text Scroll Vertical Bar

But nothing seems to automatically scroll down to the latest entry.

Here is my Bad XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <TextView android:id="@+id/shipName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginBottom="10dp" android:text="Ship Name" android:textAppearance="?android:attr/textAppearanceMedium" /> <TableLayout android:id="@+id/main" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/shipName" > <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/upgrade2Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Speed:" /> <TextView android:id="@+id/speedActual" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/shipDistance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/shipName" android:layout_below="@+id/upgrade2Name" android:text=" Distance:" android:textAppearance="?android:attr/textAppearanceSmall" /> <TextView android:id="@+id/distanceActua" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/shipDistance" android:layout_toRightOf="@+id/shipName" android:text="0" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/shipLocation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/shipName" android:layout_below="@+id/shipDistance" android:text=" Location:" android:textAppearance="?android:attr/textAppearanceSmall" /> <TextView android:id="@+id/locationActual" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/shipDistance" android:layout_toRightOf="@+id/shipName" android:text="Earth - Launch Station" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/shipFuel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/shipLocation" android:layout_below="@+id/shipLocation" android:text=" Fuel:" /> <ProgressBar android:id="@+id/fuelBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/statusActual" android:layout_alignParentRight="true" android:layout_toRightOf="@+id/shipName" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/shipStatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/shipFuel" android:layout_below="@+id/shipFuel" android:text=" Status:" /> <TextView android:id="@+id/statusActual" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/data" android:layout_toRightOf="@+id/shipName" android:text="Ready for Launch" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/data" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/shipStatus" android:layout_below="@+id/shipStatus" android:text=" Data:" /> <TextView android:id="@+id/vehicleInfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/data" android:layout_alignBottom="@+id/data" android:layout_toRightOf="@+id/shipName" android:text="0" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/researchPoints" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/data" android:layout_below="@+id/data" android:text=" Research Points: " /> <TextView android:id="@+id/vehicleMoney" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/vehicleInfo" android:layout_toRightOf="@+id/shipName" android:text="0" /> </TableRow> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" > </TableRow> </TableLayout> <LinearLayout android:id="@+id/buttons" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:gravity="center_horizontal" android:orientation="horizontal" > <Button android:id="@+id/launchButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/upgradeButton" android:layout_alignBottom="@+id/upgradeButton" android:layout_centerHorizontal="true" android:text="Launch" /> <Button android:id="@+id/upgradeButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="14dp" android:text="Upgrade" /> </LinearLayout> <ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/main" android:layout_marginLeft="40dp" android:layout_marginTop="38dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/newsFeed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollbars="vertical" android:maxLines="10" android:text="newsfeed" /> </LinearLayout> </ScrollView> 

The newsFeed is supposed to be where the scrolling occurs:

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/newsFeed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollbars="vertical" android:maxLines="10" android:text="newsfeed" /> </LinearLayout> </ScrollView> 

Thank you again.

3
  • The newsFeed is supposed be the Console. Commented Nov 23, 2013 at 6:31
  • Simple implement a listview Commented Nov 23, 2013 at 7:19
  • So instead of textview i simply say listview? And then i can just add items to the list? Commented Nov 23, 2013 at 7:45

1 Answer 1

0

Have you tried this?

scroll.fullScroll(View.FOCUS_DOWN); 

or

ScrollView scrollView = (ScrollView)findViewById(R.id.scroll); scrollView.scrollTo(0, scrollView .getBottom()); 

Syntax:

public void scrollTo (int x, int y) 

Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters:

x : the x position to scroll to

y : the y position to scroll to

http://developer.android.com/reference/android/view/View.html#scrollTo%28int,%20int%29

Sign up to request clarification or add additional context in comments.

Comments