0

I am trying to implement a android app. I have problems with TextView in a ScrollView. When I write some text into TextView according to its lenght some rows of the text at the top cannot be seen. I think they are occuluded with other things which resides in the top. Here is my xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<RadioGroup
    android:id="@+id/RadioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/SayisalRadioButton"
        android:layout_width="158dp"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/SayisalLoto" />

    <RadioButton
        android:id="@+id/SuperLotoRadioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/SuperLoto" />

</RadioGroup>

<TableRow
    android:id="@+id/KolonSayisiTableRow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/KolonSayisiEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/KolonSayisiHint"
        android:inputType="number"
        android:text="@string/Bos" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/SallaButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Uret" />

    <ProgressBar
        android:id="@+id/SonucProgressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:visibility="invisible" />

</TableRow>

<ScrollView
    android:id="@+id/SonucScrollView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center" >
    <TextView
        android:id="@+id/SonucTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:editable="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:text="@string/Bos"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</ScrollView>

</LinearLayout>

For Example when I put a text with multiple lines into the TextView with ID : SonucTextView according to its size I cannot see the some parts of the text at the top. How can I solve this problem? Is it related to the layout that I am using?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Tekin alp
  • 97
  • 1
  • 4
  • 9

3 Answers3

2

Your question is related to this one. So I suggest you check out the accepted answer.

That answer states that all you have to do is to set the maximum lines you want it to display and give it a scrollbar like so:

<TextView
    android:id="@+id/SonucTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"     
    android:editable="false"    
    android:text="@string/Bos"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:maxLines="5"
    android:scrollbars="vertical" />

And then proceed to setting the event in the code :

TexView.setMovementMethod(new ScrollingMovementMethod())

I'd like to add that the ScrollView widget is to be used when you want your entire view to scroll, not a single widget.

Hope this helps!

Community
  • 1
  • 1
Jean-Philippe Roy
  • 4,752
  • 3
  • 27
  • 41
  • Thank you for your answer. Then how can I scroll a single widget? Is there any way to scroll only some part of the display? – Tekin alp Feb 06 '12 at 20:19
  • You pointed out that when I put the vertical scroll into the Textview then the problem goes am I right? – Tekin alp Feb 06 '12 at 20:22
  • Did you check out the related question I've linked at the beginning of my answer, your problem is pretty much identical. Putting the vertical scroll isn't all there is to it, you have to add the piece of code. – Jean-Philippe Roy Feb 06 '12 at 20:29
  • Then should I remove the scrollview? – Tekin alp Feb 06 '12 at 20:53
  • Yes, you will not need the ScrollView widget. – Jean-Philippe Roy Feb 06 '12 at 20:59
  • Jean I want to ask you the line that I added to the java file "TextView.setMovementMethod(new ScrollingMovementMethod());". I am wondering what does this line do additionally? Why does not the attribute vertical scroll for TextView enough? Thank you. – Tekin alp Feb 06 '12 at 21:41
  • In my understanding, the vertical scrollbars attributes only says to the widget it should expand its text vertically if the View does become saturated, it doesn't make it scrollable by the user. For that, you need to add the ScrollingMovementMethod. – Jean-Philippe Roy Feb 07 '12 at 13:24
1

Try it:

<ScrollView
    android:id="@+id/SonucScrollView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center" >
    <TextView
        android:id="@+id/SonucTextView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" // or fixed size
        android:layout_gravity="center"
        android:editable="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:text="@string/Bos"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</ScrollView>

If you got wrap_content you can't have size to scroll it.

Namor Alves
  • 143
  • 1
  • 12
  • When I put match_parent it says you should use wrap_content in there. The eclipse suggests that. And it is not a solution for this case. – Tekin alp Feb 06 '12 at 20:20
0

Best Way

     <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/btmlyt"
        android:layout_below="@+id/deshead_tv">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           android:orientation="vertical"
           >

        <TextView
            android:id="@+id/des_tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/btmlyt"
            android:background="@android:color/white"
            android:paddingLeft="3dp"
            android:paddingRight="3dp"
            android:scrollbars="vertical"
            android:paddingTop="3dp"
            android:text="description"
            android:textColor="@android:color/black"
            android:textSize="18sp" />
        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>