How to make running text in cardview android studio? - android

I want to make layout that look like this :
It similar like Card View and Recycler View
but thing that i want to ask is how to make animation like running text inside the Card View. If the text is to long then the text start moving from right to left like running text.
This is how it looks :
I already searh in google but I can't find the exactly that i want
Your help will be appreciate,
Thanks

You need to add ellipsize property with layout_width of wrap_content or size which you define :
<TextView
android:id="#+id/attatchFilename"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/chooseFile"
android:layout_below="#id/txtMsg"
android:layout_marginTop="10sp"
android:layout_marginLeft="10dp"
android:text=""
android:singleLine="true"
android:focusable="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" />

You can do this using android:ellipsize="marquee" In you TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="30dp"
android:padding="16dp"
android:id="#+id/sliding_text_marquee"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Scrolling Text (Marquee) in Android Application"
android:textSize="24sp"
android:textStyle="bold" />

First create this animation in xml:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromXDelta="100"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100" />
Then add the animation to the TextView:
textview.startAnimation(AnimationUtils.loadAnimation(this, R.anim.scroll_animation));

Related

Display long text in single line in marqee formate without cutting text in android

I want to display long text in single line without cutting any text.
I have search many articles but does not worked.
I had try this code ,
marqee.xml in anim folder
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="10000"
android:fromXDelta="100%"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100%" />
demo.xml textview contains
<TextView
android:id="#+id/txt_tag_line"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:singleLine="true"
android:ellipsize="marquee"
android:text=" I want to display long text in single line without cutting any text."
android:gravity="center_vertical"
android:layout_alignParentRight="true"
android:textSize="36sp"/>
demo.java in java file code is
txt_tag_line = (TextView) v.findViewById(R.id.txt_tag_line);
txt_tag_line.startAnimation((Animation) AnimationUtils.loadAnimation(getActivity(),R.anim.marqee));
please tell me how do I get Full moving text in single line without cutting any word.
thanks
Use the following for your TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever" />
For the text to scroll automatically, you must call
txt_tag_line.setSelected(true);
There's no need for your custom animation.

How to prevent the TextView from being cutoff by the parent container?

I'm using mpandroidchart to generate a chart on one-third of my device screen. As I move towards the edge of the screen the TextView gets cutoff by the padding on the sides on the parent container. Is there a way to fix it without changing my UI?
Towards the edge: (gets cutoff)
Away from the edge: (appears good)
marker_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#drawable/my_marker">
<TextView
android:id="#+id/textViewMarker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text=""
android:textSize="12dp"
android:textColor="#android:color/white"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
You can apply the
android:clipChildren="false"
android:clipToPadding="false"
on your TextView's parent.
Did you tried gravity attribute?
Try this method to make the text align center.
android:gravity="center"
make sure that, use android:gravity , dont use android:layout_gravity.

Align textview in a block

I wat to create an app like this, I use textview to preview number
<TextView
android:id="#+id/generatenumber1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/generatenumber2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
How to align and color them like this, http://s24.postimg.org/sr53ezhtd/sdsd.png ?
I tried android:layout_gravity="center_vertical|right but not work.
Use android:gravity="center", and add padding to the left and right to create the whitespace between items.
Layout_gravity is used by layouts to define how they put the views inside it. Gravity is used for text/data in a view.
Try this,
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:padding="10dip"
android:text="7"
android:textColor="#fff" />

Android - Linear/Relative Layout, same line and next line

So, I'm currently in the process of creating my first Android app. It's been a difficult battle, but I'm somehow hanging in there. Stuck on the design now though.
<?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="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/phid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<ImageView
android:id="#+id/color"
android:contentDescription="paintable circle"
android:layout_width="18dp"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginLeft="6dip"
android:layout_marginTop="6dip"
android:src="#drawable/circle" />
<TextView
android:id="#+id/datetime"
android:layout_width="wrap_content"
android:layout_height="60dip"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingRight="10dp"
android:paddingTop="10dip"
android:textSize="12sp"
android:textStyle="bold" />
This gives a nice list, with the title in the top left, and the date in the far top right. But I want a textview under the title, same font size as the datetime, and another textview under the datetime with the same font size. I've tried adding another LinearLayout, a RelativeLayout, without any extra Layouts, but it just doesn't seem to work. What am I missing here? Thanks.
You could use a RelativeLayout
place the title on the top left
android:layout_alignParentLeft = "true"
place the date time on the right with
android:layout_alignParentRight = "true"
Then for each of the TextViews you want to place under a component, use
android:layout_below = (give the id of the control )
Cheers

Horizontal scrolling text in Android

I've been looking around for quite some time now, and I can't get a straight answer for my question.
It's quite simple: How can I get a nice scrolling text just like the long app names in the Market when you select an application?
I've figured it out by myself.
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
Make a translate animation in your anim folder like:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="12000"
android:fromXDelta="100"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100" />
And then to your textview like:
yourtextview.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.youranim_xml));
Hope this might help you.
Edit:
Try this:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:padding="4dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Simple application that shows how to use marquee, with a long text" />
the decision which works for me:
textView.setSelected(true);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setSingleLine(true);
without focusable's parameters
android:ellipsize="marquee"
Use a normal TextView with the following config:
android:text="your text here"
android:id="#+id/MarqueeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" />
The problem with this is that you cannot adjust the speed of the scrolling text.
Enclose a TextView within a ScrollView:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/myTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your Text here" >
</TextView>
</ScrollView>
Create custom class and follow this thread

Categories

Resources