marquee in Android - android

I want to marquee the textview but am not getting success to do it properly. Though i have gone through some examples give in stackoverflow, but still having problem. can anybody help?

try this it is working for me
<TextView
android:text="Android Marquee"
android:id="#+id/MarqueeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true">
</TextView>

It is the minimum code to create a marque -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/MarqueeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="This is a very long text which is not fitting in the screen so it needs to be marqueed."
android:textAppearance="?android:attr/textAppearanceLarge" />
To make your marque more presentable view this:
http://yhisham.blogspot.in/2012/08/android-how-to-make-marquee-ticker.html

Related

Scrolling textview is not scrolling, in Android.

I'm making my text scrolling as the post here.
I think I saw it was scrolling first time in another layout even without any java code.
But now, it's not scrolling anymore. No idea what's wrong with this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<LinearLayout
android:id="#+id/scrollingTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#0792B5"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/scrollingText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="1"
android:padding="5dp"
android:scrollHorizontally="true"
android:text="The culture of India is the way of living of people of India."
android:textColor="#FFFFFF"
android:textSize="16sp" />
</LinearLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/scrollingTextLayout"
android:background="#android:color/darker_gray" />
</RelativeLayout>
just put these lines in your xml:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:scrollHorizontally="true"
And in your code:
textView.setSelected(true);
It's now scrolling. I just changed maxLines="1" to singleLine="true" , you know it's a little weird. I changed singleLine to maxLines because the IDE suggested me to use maxLines instead of singleLine since it's deprecated already.
Add this code in Activity
TexView tv=findViewbyId(R.id.scrollingText);
tv.setSelected(true);

Android App Widget - How To Create TextView Marquee On Two Separate Lines With Adjustable Scrolling Speeds?

I'm trying to create a widget with several different lines on it and want to set it to auto scroll (marquee) and have the ability to adjust the scrolling speed. How can I accomplish this?
I tried using a TextView and was able to make it scroll on one line, but that's it. I can't seem to adjust the speed of it or have two lines scrolling at the same time.
An example of this is: https://play.google.com/store/apps/details?id=huntsman.stocktickertapelite&hl=en
OR
https://play.google.com/store/apps/details?id=com.cousinHub.widget
Anyone have an idea of how they did it? (custom views?)
Thanks.
This is what I have so far:
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textStyle="bold"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/app_name"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true"
android:layout_weight="1">
<requestFocus
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
Try this, I am getting the text from Java as setText file, and show in this screen
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/line_dotted"
android:layout_marginBottom="10dp"
android:fillViewport="true"
android:scrollbars="vertical" >
<TextView
android:id="#+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15sp"
android:layout_marginRight="15sp"
android:layout_marginTop="10sp"
android:scrollbars="vertical"
android:textColor="#0A2A1B"
android:textSize="12sp" />
</ScrollView>
Or You can try this without scrollview, the text will scroll when there is more than 5 ines
<EditText
android:id="#+id/Comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Submitbtn"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ratingBar"
android:layout_marginBottom="40dp"
android:ems="10"
android:gravity="left"
android:hint="Comments"
android:maxLines="5"
android:padding="20dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:imeOptions="actionDone" />

ellipsize on textview doesnt work

I want to display ellipsis if my textview length is too long. But for some reason, it doesnt seem to work. Please take a look at the image on how it looks like:
Here is my layout code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt1_trans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:bufferType="spannable"
android:layout_marginLeft="10dp"
android:singleLine="true"
android:ellipsize="end"
android:freezesText="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="My Personal > Bank of America savings"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:id="#+id/TextView2"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="100$"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/txt1_trans"
android:layout_alignBottom="#id/txt1_trans"/>
</RelativeLayout>
I want the textView on the left (txt1_trans) to display ellipsis if it takes up the space that textview on the right ("TextView2") occupies. Please let me know what I am doing wrong.
Thanks
You can't use ellipsize with wrap_content as the width. You need to use either wrap_parent or preferably match_parent depending on what version of Android you're targeting.
I found the problem with the layout. For the 2nd TextView on my layout, I have set
alignParentRight = true
And the 1st TextView has
width = "wrap_content"
Because of this, both these TextViews end up taking up common space. In order to avoid that, I set the first TextView to_LeftOf 2nd TextView . This ensures that they dont try to write on the same common space . Here is my correct layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt1_trans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:bufferType="spannable"
android:layout_marginLeft="10dp"
android:singleLine="true"
android:ellipsize="end"
android:layout_toLeftOf="#+id/TextView2"
android:freezesText="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="My Personal Bank of America savings"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:id="#+id/TextView2"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="100$"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/txt1_trans"
android:layout_alignBottom="#id/txt1_trans"/>
</RelativeLayout>

Android Widget: Textview stops marquee on homepage scroll

I have a text view in my widget that scrolls the text like a marquee. Now, it works in normal state. But, if i scroll(swipe) through my home screen for other pages, then this textview stops scrolling. Any Idea how to solve this?
My xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="8dip"
android:background="#drawable/myshape" >
<TextView
android:id="#+id/update"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="25dp" >
<requestFocus
android:duplicateParentState="true"
android:focusable="true"
android:focusableInTouchMode="true" />
</TextView>
</LinearLayout>
Thanks.
Your xml looks ok,
in your resume method
try add
textview_update.setSelected(true);
also, I had found some small devices can't handle textview that has length over 1024 otherwise it will stop (when memory is full)

How to add marquee effect to listview?

I have list of my friends in ArrayList & i am trying to display it in listview using ArrayAdapter & rowlayout.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/rowlayout"
android:padding="10dp"
>
Now i want to add marquee effect to it.I want to scroll this listview forever.
For this i added following code
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:scrollHorizontally="true"
android:singleLine="true"
But this code stop my OnLongClickListner effect of listview.
I don't know why?
android:ellipsize="marquee"
android:gravity="left"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine is depricated,focusable -not needed too
This layout works in a new sample project:
<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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:scrollHorizontally="true"
android:text="12312312321321312312321321312311321321321312321312312123132132132" />
</RelativeLayout>

Categories

Resources