Android: Adding Vertical Scroll to TextView - android

I'm trying to set up a TextView vertical scroll in the XML layout, it barely works, The scroll seems to move when I hardly swipe down the vertical bar, I mostly get to scroll down the layout instead of the textview, it's difficult.
I attached my code below.
<TextView
android:id="#+id/evento_descripcion"
android:layout_width="match_parent"
android:layout_height="150dp"
android:text="#string/t_descripcion"
android:textColor="#010101"
android:layout_below="#+id/evento_fondo"
android:textSize="16sp"
android:layout_marginTop="20dp"
android:gravity="left"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideInset"
/>

Try adding this to your code
YOURTEXTVIEW.setMovementMethod(new ScrollingMovementMethod());
Also check this and this out, I think it will help you.

Related

TextView in HorizontalScrollView not scrolling automatically when text is added

I have a TextView that takes in Strings and I want the TextView to scroll to the last text added on the right automatically. The ScrollView works but I have to scroll manually to the last text added when it's out of the TextView's field of view. Please help.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"
android:fillViewport="true"
android:scrollbars="none">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:scrollHorizontally="true"
android:textColor="#android:color/black"
android:textSize="24sp" />
</HorizontalScrollView>
yourScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
I solved this problem through the use EditTextView instead of TextView and disabling focusEnabled by setting keyListener to null in order to achieve the behavior of a normal TextView and also scroll automatically like I wanted.

Cannot independently set padding on TextViews

While testing some designs for a LinearLayout for the elements in a ListView, I stumbled upon some weird behaviour. As you can see in the added code, I have three TextViews in a horizontal LinearLayout. I wanted to set the padding for one of these TextViews, but it seems that this value is also applied to the other TextViews as a margin of some sort (see pictures).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp">
<TextView
android:id="#+id/search_list_row_symbol"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
android:textSize="16sp"
android:background="#android:color/holo_blue_light"
android:text="O"/>
<TextView
android:id="#+id/search_list_row_name"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
android:textSize="16sp"
android:background="#android:color/holo_red_light"
android:text="oxygen"/>
<TextView
android:id="#+id/search_list_row_number"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
android:textSize="16sp"
android:background="#android:color/holo_green_light"
android:text="8"/>
</LinearLayout>
Set android:paddingTop="0dp" on all TextViews
Set android:paddingTop="16dp" only on first TextView
Do any of you know why the padding cannot be set independently on one of these TextViews?
The behavior seems correct as padding is applied to the content of a view - not to the view itself. However, the remaining child views following the padding from first child view seems erroneous.
As an alternate, I would suggest you to replace paddingTop with layout_marginTop and it should work fine.
Because you have given padding to only one text view. If you want all text view than you will have to keep all three within one LinearLayout and set property i.e setPadding() or setPaddingTop().
I think this might help you.

Horizontally Scrollable TextView show inconsistent behaviour across android versions

I have a text view that has a single lined Arabic (Right-to-Left) text. The Text content increases by time, and the last (left-most) part should always appear. The horizontal scroll bar is initially set to right, and auto scrolls to left as text increases.
The below code works great on a 2.3 Android phone.
This comes from the layout.xml
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:fadingEdge="horizontal"
android:gravity="right"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:singleLine="true"
android:text="#string/txt_start"
android:textAppearance="?android:attr/textAppearanceLarge" />
I have this in the onCreate() method of my Activity
tv = (TextView) findViewById(R.id.textView1);
tv.setMovementMethod(new ScrollingMovementMethod());
The problem is the inconsistent behaviour of the text view on phones having android 4.0+ . The horizontal scroll bar is initially no placed on the right, so the TextView is initially blanked! If I try to scroll the blank textView, the text shows up. When extra text is added, the scroll-bar is not scrolled to show the new text, but if I manually scrolled the text, it appears.
I searched stackoverflow, and tried to add the below properties with no success.
android:focusable="true"
android:focusableInTouchMode="true"
None of those solutions worked in my case where I wanted to animate scrolling of TextView with android:gravity="right". Simple workaround that helped though is to keep TextView gravity to left but place it aligned to right inside a RelativeLayout container:
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoScrollingTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="left"
android:singleLine="true"
android:ellipsize="none">
</RelativeLayout>
Try this example, it should work:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/myscroll"
android:ellipsize="marquee"
android:singleLine="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="10"
>
</LinearLayout>
Note: when testing the marquee, don't test it in design view inside Eclipse, try it on the emulator\device ..
Also if you want to add a scrolling effect in code:
TextView tView = (TextView) findViewById(R.id.myText);
tView.stSelected(true);
To make the marquee scroll non-stopping on the end of marquee:
android:marqueeRepeatLimit=”marquee_forever”
It's found that the gravity Left/Right are deprecated, a developer should use Start/End. For the text to scroll it needs a "wrap_content" set to its width, additionally the textDirection needs to be set to RTL. For unknown reasons, textDirection did not work programmatically, but worked in the xml.
This code works well on all API versions of android.
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:textDirection="rtl"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:singleLine="true"
android:ellipsize="none"
android:text="#string/txt_start"
android:textAppearance="?android:attr/textAppearanceLarge" />

Android: LinearLayout Rearranged when updating views

I'm having a problem with a LinearLayout in an app i'm working on. The linear layout is vertical. There are several items in the layout including a TextView, a vertical SeekBar, and an ImageView.
Whenever I update the textView (ie setText()) my layout rearranges. The ImageView goes from being at the bottom to being in the middle. Same thing happens if I replace the drawable in the ImageView.
I assume I have something wrong with how I am specifying my layout. This is the portion having problems:
<modrobotics.code.ui.BlockValueSliderView
android:id="#+id/sliderSix"
android:layout_width="0dp"
android:visibility="gone"
android:layout_height="fill_parent"
android:layout_marginBottom="-12dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/BVLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:paddingTop="12dp"
android:text="64"
android:textColor="#000"
android:textSize="20sp" >
</TextView>
<View
android:id="#+id/circle1"
android:layout_width="6dp"
android:layout_height="6dp"
android:layout_gravity="center"
android:layout_marginBottom="-6dp"
android:background="#drawable/circle"
android:gravity="center_horizontal"
android:padding="0dp" />
<LinearLayout
android:id="#+id/controlElementList12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="0dp" >
<modrobotics.code.ui.VerticalSeekBar
android:id="#+id/slider"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="-20dp"
android:layout_weight="20"
android:padding="0dp"
android:progressDrawable="#drawable/seekbar_progress"
android:thumb="#drawable/seekbar_thumb"
android:thumbOffset="-1dp" />
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="-20dp"
android:layout_marginTop="-20dp"
android:layout_weight="1"
android:padding="0dp"
android:src="#drawable/on6" >
</ImageView>
</LinearLayout>
</modrobotics.code.ui.BlockValueSliderView>
EDIT:
I have tried the suggestions mentioned below to no avail. I have removed all negative margins, simplified the layout by removing unnecessary LinearLayout, gotten rid of GONE, fixed height for images etc... I'm starting to believe the problem is greater than just this.
I'm using a single Activity with a PageAdapter. It seems I'm not using PageAdapter correctly. startUpdate() is being called over and over again. Any static global variables I have seem be cleaned up or on separate threads some how. I believe these problems may all be linked. Perhaps I don't full understand the threading model when using a PageAdapter.
In 'modrobotics.code.ui.BlockValueSliderView' change the visiblity from GONE to INVISIBLE. It's possible that the layout elements will re-arrange whenever you change the visibility programatically from GONE to VISIBLE of this View because while the View is set to be GONE, it doesn't occupy any space in the layout and rest of the Views are placed in the layout just taking its space. If it's GONE, It behaves like it doesn't exist in the layout. Then, when you sets this view to be VISIBLE, it switches rest of the Views in the layout to prepare a space for itslef.
This turned out to be a problem related to the VerticalSeekBar implementation I was using.
I was rotating the thumb for the seekbar, and also calling bringToFront() on the seekbar. The combination of these two calls caused elements to be rearranged. Not to sure why, but removing these two lines of code fixed my problems.

Scroll a text automatically on horizontal

I want to scroll a text automatically in horizontal way. I tried the method below, but the text was not scrolling.
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bg_1"
android:textColor="#cc0000"
android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
/>
So please tell me how to scroll a text and if there is any need to add some code in the class file also.
your TextView don´t scroll because their with must be fill_parent, and the other thing is that the textview must be selected (not pressed) to scroll.
Also, beside what Franco told you, you have set android:ellipsize="marquee"(that truncate the text to fit on that single line you have set), so probably that mix up with the scrolling you set by android:scrollHorizontally="true"
My suggestion is to try to remove the ellipsize property.
i put a listview in above textview so the textview is not scrolling. so itried this one
set listview focusable is false
listview.setfocusable(false);
then it works the text was scrolling.
Try this....
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="John Jonathan Samuwell Abbruzzi"
android:singleLine="true"
android:scrollHorizontally="true"
android:textSize="50sp" />
</HorizontalScrollView>

Categories

Resources