Unable to slide vertical scrollbar

  • Replies:3
Daniel K.
  • Forum posts: 4

May 16, 2012, 5:26:42 PM via Website

I'm new to android development, so unsure if this is the best way to do what I want, so feel free to provide suggestions. What I want to do is simply just display some verbose text messages to the screen that will scroll and allow the user to slide up and down vertically so they can view any of the messages.

I've spent the past few days trying everything I can find on Google and I still have yet to get anything working. I have been able to successfully have the text display, append to the previous text, and scroll on its own. The common issue I have seen with my working implementations has been the ability of the user being able to scroll the vertical scroll-bars themselves. I have implemented the object properties in the xml, as well as in code, but neither have worked and I'm assuming it is just a noob mistake or some little thing i'm missing.

I have tried both a TextView as well as an EditText object. I have used them in Scrollviews, by themselves but nothing seems to work. I would prefer to use the EditText with scrollbars, but at this point I am up for anything that works. I am pasting what I have currently using the EditText. I have removed the scrollview below just to start with a simpler base.

If anyone has any ideas for what will solve my issue please let me know. I also have a device on order so I do not have the ability to try on hardware yet, so I am doing this all in the droid emulator. Unsure if that is a problem.

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="hxxp://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
6
7 <EditText
8 android:id="@+id/path"
9 android:layout_width="fill_parent"
10 android:layout_height="wrap_content" />
11
12 <org.apache.android.media.CustomVideoView
13 android:id="@+id/custom_videoview"
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:layout_weight="3.33" />
17
18 <EditText
19 android:id="@+id/MessageText"
20 android:layout_width="match_parent"
21 android:layout_height="wrap_content"
22 android:ems="10"
23 android:inputType="textMultiLine" android:layout_marginTop="100dp" android:scrollbars="vertical" android:fadeScrollbars="false" android:gravity="top" android:maxHeight="100dp" android:textSize="10sp">
24
25 <requestFocus />
26
27 </EditText>
28
29</LinearLayout>

Reply
Daniel K.
  • Forum posts: 4

May 17, 2012, 2:45:44 PM via Website

Jeremiah
To get the scrollbars to actually work you have to have this in your code: TexView.setMovementMethod(new ScrollingMovementMethod());

Here is a post on the question: http://stackoverflow.com/questions/2478615/android-textview-with-scrollbars-and-maxheight

Thanks for the reply Jeremiah. I actually do have that in my code and it was my fault for not posting that I did, so I apologize. In my onCreate I have the below code which includes the line you have above. As you can see in the commented code I had also tried with and without the toher lines, but it still doesnt seem to pick up me trying to scroll the vertical scrollbar. Thanks again though for the reply.

1mMessageText = (EditText) findViewById(R.id.MessageText);
2 //mMessageText.setScroller(new Scroller(this.getApplicationContext()));
3 //mMessageText.setVerticalScrollBarEnabled(true);
4 mMessageText.setMovementMethod(new ScrollingMovementMethod());

Reply
Jeremiah
  • Forum posts: 775

May 18, 2012, 12:46:00 AM via Website

I think the problem is that you can not do this with an EditText, change it to TextView and it should work. You don't need them to input anything into the message text do you?

Also add a maxLines to your textview:

<TextView
android:id="@+id/MessageText"
android:layout_width="match_parent"
android:layout_height=""wrap_content"
android:ems="10"
android:layout_marginTop="100dp"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:gravity="top"
android:maxHeight="100dp"
android:textSize="10sp"
android:maxlines=10>

— modified on May 18, 2012, 12:55:07 AM

Reply