In have the many textview which may have very long text so have done
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:singleLine="true"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
For first text view it works fine but for other it is not working, if anyone have done it for other textview in activity then please help me.
Thank you.
It is very easy extend your class with TextView and override following methods
package com.az.app;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
public class ScrollingTextView extends TextView {
public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollingTextView(Context context) {
super(context);
}
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
#Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
#Override
public void onWindowFocusChanged(boolean focused) {
if (focused)
super.onWindowFocusChanged(focused);
}
#Override
public boolean isFocused() {
return true;
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
and in your XML do this
<com.az.app.ScrollingTextView
android:id="#+id/TextView02"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView01"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="This is a really very very very very very long text "
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<com.az.app.ScrollingTextView
android:id="#+id/TextView03"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView01"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="This is a really very very very very very long text "
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
Now all the textviews will be scrolling.
Update:
Note that it doesn't work without android:singleLine="true".
Use it with android:maxLines="1", Although we know that it's deprecated.
#Sathish Yes you can, i've done it. Following is my code for two marquee textview in xamarin.android
xml
<TextView
android:text=""
android:singleLine="true"
android:background="#cc2900"
android:ellipsize="marquee"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:layout_marginLeft="1dp"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:id="#+id/TextView03"
android:padding="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:text=""
android:singleLine="true"
android:background="#cc2900"
android:ellipsize="marquee"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:layout_marginLeft="1dp"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:id="#+id/txtinternational"
android:padding="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
and in your activity you just have to set focus to your all textviews:
TextView shorts = FindViewById<TextView>(Resource.Id.TextView03);
shorts.Selected = true;
TextView internationalshorts = FindViewById<TextView>(Resource.Id.txtinternational);
internationalshorts.Selected = true;
Related
I'm making a music player and have implemented a marquee for the song and artist name. But as soon as the seek bar gets updated, the text view comes back to the original position. So in this way, a kind of back and forth motion of text is seen.
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainFullPlayerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.musicplayer.integrated.sanket.music.MainFullPlayer"
android:background="#color/defaultBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/imageView_full_player_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:layout_marginRight="15dp"
app:srcCompat="#drawable/icon_more" />
</RelativeLayout>
<ImageView
android:id="#+id/imageView_full_player_album_art"
android:layout_width="300dp"
android:layout_height="300dp"
app:srcCompat="#drawable/default_album_art"
android:layout_marginTop="29dp"
android:layout_below="#+id/relativeLayout"
android:layout_centerHorizontal="true" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressTint="#color/defaultTextColor"
android:thumbTint="#color/defaultTextColor"
android:layout_above="#+id/imageView_full_player_play"
android:layout_marginBottom="37dp" />
<ImageView
android:id="#+id/imageView_full_player_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp"
app:srcCompat="#drawable/icon_play_small" />
<ImageView
android:id="#+id/imageView_full_player_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView_full_player_play"
android:layout_marginStart="39dp"
android:layout_toEndOf="#+id/imageView_full_player_play"
app:srcCompat="#drawable/icon_fast_next_small" />
<ImageView
android:id="#+id/imageView_full_player_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView_full_player_play"
android:layout_marginEnd="38dp"
android:layout_toStartOf="#+id/imageView_full_player_play"
app:srcCompat="#drawable/icon_rewind_prev_small" />
<TextView
android:id="#+id/textView_full_player_song"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/imageView_full_player_album_art"
android:layout_alignStart="#+id/imageView_full_player_album_art"
android:layout_below="#+id/imageView_full_player_album_art"
android:layout_marginTop="12dp"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Song Name"
android:textAlignment="center"
android:textColor="#color/defaultTextColor"
android:textSize="18sp" />
<TextView
android:id="#+id/textView_current_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0:00"
android:textColor="#color/defaultTextColor"
android:textSize="12sp"
android:layout_marginBottom="18dp"
android:layout_above="#+id/imageView_full_player_prev"
android:layout_alignStart="#+id/textView_full_player_artist" />
<TextView
android:id="#+id/textView_total_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5:00"
android:textSize="12sp"
android:textColor="#color/defaultTextColor"
android:layout_alignBaseline="#+id/textView_current_time"
android:layout_alignBottom="#+id/textView_current_time"
android:layout_alignEnd="#+id/textView_full_player_artist" />
<TextView
android:id="#+id/textView_full_player_artist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView_full_player_song"
android:layout_alignStart="#+id/textView_full_player_song"
android:layout_below="#+id/textView_full_player_song"
android:layout_marginTop="12dp"
android:text="Artist"
android:textAlignment="center"
android:textColor="#color/defaultTextColor"
android:textSize="15sp"
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:scrollHorizontally="true"
/>
</RelativeLayout>
Here is my Java code:
public class MainFullPlayer extends AppCompatActivity {
private static RelativeLayout fullPlayer;
private static ImageView fullPlayer_play , fullPlayer_next ,
fullPlayer_prev,fullPlayer_album;
private static TextView fullPlayer_song , fullPlayer_artist ,
fullPlayer_currentTime , fullPlayer_maxTime;
private static SeekBar seekBar;
private Songs song;
private static Handler progressHandler;
private static Runnable progressRunnable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_full_player);
fullPlayer = (RelativeLayout)findViewById(R.id.mainFullPlayerContainer);
fullPlayer_play = (ImageView)findViewById(R.id.imageView_full_player_play);
fullPlayer_next = (ImageView)findViewById(R.id.imageView_full_player_next);
fullPlayer_prev = (ImageView)findViewById(R.id.imageView_full_player_prev);
fullPlayer_album = (ImageView)findViewById(R.id.imageView_full_player_album_art);
fullPlayer_song = (TextView)findViewById(R.id.textView_full_player_song);
fullPlayer_artist = (TextView)findViewById(R.id.textView_full_player_artist);
fullPlayer_currentTime = (TextView)findViewById(R.id.textView_current_time);
fullPlayer_maxTime = (TextView)findViewById(R.id.textView_total_length);
fullPlayer_maxTime.setText(MusicPlayback.getTime(MusicPlayback.mediaPlayer.getDuration()));
seekBar = (SeekBar)findViewById(R.id.seekBar);
song = MusicPlayback.allTracks.get(MusicPlayback.songPosition);
fullPlayer_song.setSelected(true);
fullPlayer_artist.setSelected(true);
fullPlayer_song.setText(song.getSongName());
fullPlayer_artist.setText(song.getArtist());
if(MusicPlayback.getPlayingStatus()){
fullPlayer_play.setImageResource(R.drawable.icon_pause_small);
}
else
{
fullPlayer_play.setImageResource(R.drawable.icon_play_small);
}
if(song.getAlbumArt()!= null){
fullPlayer_album.setImageURI(Uri.parse(song.getAlbumArt()));
fullPlayer.setBackground(FragmentAllTracks.d);
}
else{
fullPlayer_album.setImageResource(R.drawable.default_album_art);
fullPlayer.setBackgroundColor(Color.argb(255, 48, 48, 48));
}
seekBar.setMax(MusicPlayback.mediaPlayer.getDuration());
progressHandler = new Handler();
progressRunnable = new Runnable() {
#Override
public void run() {
seekBar.setProgress(MusicPlayback.mediaPlayer.getCurrentPosition());
fullPlayer_currentTime.setText(MusicPlayback.getTime(MusicPlayback.mediaPlayer.getCurrentPosition()));
progressHandler.postDelayed(progressRunnable,100);
}
};
progressHandler.postDelayed(progressRunnable,100);
}
#Override
public void onBackPressed() {
super.onBackPressed();
this.overridePendingTransition(R.anim.left_exit_translate,R.anim.right_exit_translate);
}
}
Here is the result:
Try to use this MarqueeTextView class, it automatically set fixed size for TextView so it won't re-measure (the reason cause restart scroll animation):
public class MarqueeTextView extends AppCompatTextView implements View.OnLayoutChangeListener {
public MarqueeTextView(Context context) {
this(context, null);
}
public MarqueeTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setSingleLine();
setEllipsize(TextUtils.TruncateAt.MARQUEE);
setMarqueeRepeatLimit(-1);
setSelected(true);
addOnLayoutChangeListener(this);
}
#Override
public boolean isFocused() {
return true;
}
#Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
if (hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus);
}
#Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (focused) super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
#Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
ViewGroup.LayoutParams layoutParams = getLayoutParams();
layoutParams.height = bottom - top;
layoutParams.width = right - left;
removeOnLayoutChangeListener(this);
setLayoutParams(layoutParams);
}
}
I had the same problem. It happens because of this line inside the runnable:
fullPlayer_currentTime.setText(MusicPlayback.getTime(MusicPlayback.mediaPlayer.getCurrentPosition()));
I found the answer here: https://stackoverflow.com/a/13841982/10334697.
You have to set fixed size for your TextView.
I think its because of focus. Please set your textview like this
<TextView
android:id="#+id/textView_full_player_song"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/imageView_full_player_album_art"
android:layout_alignStart="#+id/imageView_full_player_album_art"
android:layout_below="#+id/imageView_full_player_album_art"
android:layout_marginTop="12dp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:text="Song Name"
android:textAlignment="center"
android:textColor="#color/defaultTextColor"
android:textSize="18sp" />
add this your TextView,
android:focusable="true"
android:focusableInTouchMode="true"
I want to create a LinearLayout with two TextViews: a label and a data placeholder. Since the data can be arbitrarily long, I want to restrict the size of the second TextView to a single line, and to automatically scroll horizontally if the data does not fit in the view.
Also, I want the width of the second TextView to be calculated at runtime, so that it can fill 70% of the parent container and be aligned to its right.
So far this is what I've got:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/ll_denunciante" >
<TextView
android:id="#+id/txtv_label_denunciante"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="left"
android:text="#string/txtv_label_denunciante" />
<TextView
android:id="#+id/txtv_data_denunciante"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="right"
android:maxLines="1"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:text="#string/txtv_no_data" />
</LinearLayout>
But the text is simply cut off. It is not ellipsized and automatic scrolling does not work.
Adding
android:focusable="true"
android:focusableInTouchMode="true"
does not fix the problem.
The answer to this question did not help either.
I'll gladly accept an answer using a RelativeLayout if it accomplishes the desired result using less code or if it is not possible using a LinearLayout.
Edit
Changing the second TextView to:
<TextView
android:id="#+id/txtv_data_denunciante"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:ellipsize="marquee"
android:gravity="right"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="#string/txtv_no_data" />
and adding
txtvDataDenunciante.setSelected(true);
fixed it.
I tried this way and it works. Replace your 2nd TextView with the one below. Here is the Result in the attached screenshot.
<TextView
android:id="#+id/txtv_data_denunciante"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:ellipsize="marquee"
android:gravity="right"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="1"
android:singleLine="true"
android:freezesText="true"
android:text="#string/txtv_no_data"
android:selectAllOnFocus="true" />
EDIT : If XML attributes don't work in your case, then the problem is about taking the focus. In some cases, parent Layouts or some others take the focus on theirself. So you need to gain the focus for the particular View element yourself on the RunTime. To do that, you can set your TextView as selected.
yourTextView.setSelected(true);
If it is in a ListView, the problem is that you TextView does not get the focus.
Change your TextView to use this one :
public class AutoScrollingTextView extends TextView {
public AutoScrollingTextView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public AutoScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AutoScrollingTextView(Context context) {
super(context);
}
#Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
if (focused) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}
#Override
public void onWindowFocusChanged(boolean focused) {
if (focused) {
super.onWindowFocusChanged(focused);
}
}
#Override
public boolean isFocused() {
return true;
}
}
With these parameters :
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
As seen here : https://stackoverflow.com/a/9707140/1318795
When I was working on a new view yesterday I had 7*4 Edit texts , so I had to add lots of code to cover them when the user tries to change the color , for example Red
So I was thinking to do something like this:
if(item.getItemId() == R.id.menu_table_colors_Red){
EditText Holder = (EditText)mView.findViewById(View_ID);
Holder.setBackgroundResource(R.color.RED);
return true;
}
The View_ID is from onCreateContextMenu() which tells me which view was clicked on and mView is my fragment view , it works fine and all until I needed to save the values of the colors so the user can return and find the colors that he used:
I found two ways after searching either with a way in 11 api but I need a way to work on 8 api and higher.
the second was to implement a custom Edittext class , I copied the class from the solution to test it and here it is:
public class NewEditText extends EditText {
private int color;
public NewEditText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public NewEditText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public NewEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
#Override
public void setBackgroundColor(int color) {
// TODO Auto-generated method stub
this.color=color;
super.setBackgroundColor(color);
}
public int getBackgroundColor() {
return color;
}
}
but I'm not sure how to use this ? when I do this it crashes because of " class cast exception "
NewEditText holder = (NewEditText)mView.findViewById(View_ID);
how am I supposed to use this ? sorry but I've never used a custom class and I couldn't find a solution.
Edit 1 the xml , sorry it's kinda big so I decided to post one of the days since there are 7 days and they're the same:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:id="#+id/table_view_mondaylayout"
android:layout_margin="0.3dp"
>
<TextView
android:layout_width="32dp"
android:layout_height="match_parent"
android:text="Mon"
android:layout_weight="0"
android:gravity="center"
android:background="#drawable/custom_table"
android:layout_margin="0.3dp"
/>
<EditText
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="125 \n down"
android:textSize="14sp"
android:layout_weight="1"
android:background="#drawable/custom_table"
android:id="#+id/table_monday1"
android:layout_margin="0.3dp"
/>
<EditText
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="125 \n down"
android:textSize="14sp"
android:layout_weight="1"
android:background="#drawable/custom_table"
android:id="#+id/table_monday2"
android:layout_margin="0.3dp"
/>
<EditText
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="125 \n down"
android:textSize="14sp"
android:layout_weight="1"
android:background="#drawable/custom_table"
android:id="#+id/table_monday3"
android:layout_margin="0.3dp"
/>
<EditText
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="125 \n down"
android:textSize="14sp"
android:layout_weight="1"
android:background="#drawable/custom_table"
android:id="#+id/table_monday4"
android:layout_margin="0.3dp"
/>
</LinearLayout>
I'm having an issue where I have a ScrollView content inside of it. In the event that the content doesn't all fit on screen, I want it to scroll. However, if it all fits I don't want it to scroll.
As is, the scrollviewer scrolls quite a bit and all the content can be scrolled way off screen.
How does one get the scrollview to not scroll when all the content fits on the screen?
<ScrollView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/productImageView"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:id="#+id/detailsScrollView"
android:paddingRight="24dp"
android:paddingLeft="24dp"
android:clipChildren="true"
android:fillViewport="true"
android:measureAllChildren="true">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:paddingTop="24dp"
android:paddingBottom="24dp">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/patternTitleTextView" />
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/designerNameTextView"
android:textColor="#color/default_gray" />
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/descriptionTextView"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:minLines="200"
android:scrollbars="none"
android:scrollHorizontally="false"
android:singleLine="false"
android:ellipsize="none" />
</LinearLayout>
</ScrollView>
You probably need to create a custom ScrollView:
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class CustomScrollView extends ScrollView {
private boolean enableScrolling = true;
public boolean isEnableScrolling() {
return enableScrolling;
}
public void setEnableScrolling(boolean enableScrolling) {
this.enableScrolling = enableScrolling;
}
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomScrollView(Context context) {
super(context);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (isEnableScrolling()) {
return super.onInterceptTouchEvent(ev);
} else {
return false;
}
}
}
Then you can do something similar to this in your code:
CustomScrollView myScrollView = (CustomScrollView) findViewById(R.id.myScroll);
myScrollView.setEnableScrolling(false); // disable scrolling
myScrollView.setEnableScrolling(true); // enable scrolling
Of course, it will be up to you to decide when exactly you need to enable/disable scrolling.
The problem in my case was with one of the TextViews.
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/descriptionTextView"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:minLines="200"
android:scrollbars="none"
android:scrollHorizontally="false"
android:singleLine="false"
android:ellipsize="none" />
I shouldn't have set minLines or set the layout_weight. After removing those two things the scrollview did exactly what I expected it to.
How come the following code not working. I have something similar at other part of the layout and it works. But this part does not work. Any idea?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_gravity="center_vertical"
android:id="#+id/statusTvBottom"
android:text="Status: "
android:layout_marginLeft="5dp">
</TextView>
</LinearLayout>
First, the text has to be longer than the "box" in order to marquee, if it fits-no marquee. I use this code:
<TextView
android:id="#+id/availability"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical|center_horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#343434"
android:textSize="#dimen/text_size_medium"
android:textStyle="bold|italic" />
Setting android:focusable="false" and android:focusableInTouchMode="false" allows it to marquee without focus.
First, you can try this:
textview.setSelected(true);
But it might not work when the text view can't get the focus all the time. So, to ensure TextView Marquee working, I had to use a custom TextView.
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
#Override
public void onWindowFocusChanged(boolean focused) {
if(focused)
super.onWindowFocusChanged(focused);
}
#Override
public boolean isFocused() {
return true;
}
}
And then, you can use the custom TextView as the scrolling text view in your layout .xml file like this:
<com.example.myapplication.CustomTextView
android:id="#+id/tvScrollingMessage"
android:text="#string/scrolling_message_main_wish_list"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/black"
android:gravity="center"
android:textColor="#color/white"
android:textSize="15dp"
android:freezesText="true"/>
NOTE: in the above code snippet com.example.myapplication is an example package name and should be replaced by your own package name.
Hope this will help you. Cheers!