I have a ListView and I want that when I click on a ListView item, the bottom TextView change its value and if the text is too large it's autoscrolling.
1) HorizontalScrollView cuts off the text, the original text is "Enrique Iglesias - Bailando ft. Descemer Bueno, Gente De Zona", but there's no space so I see only "Enrique Iglesias - Bailando ft.". Now, I want that with scrolling I see also " Descemer Bueno, Gente De Zona", but there is not... the TextView value is correct, there is the full name, I see with logs...
What I see:
What I see clicking on the TextView:
2) Autoscrolling not working, I have to click on the TextView for scrolling.
This is my code layout:
titleSongPlayngTextView = (TextView) rootView.findViewById(R.id.song_title);
titleSongPlayngTextView.setMovementMethod(new ScrollingMovementMethod());
final HorizontalScrollView s = (HorizontalScrollView)
rootView.findViewById(R.id.title_scroller);
s.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
This is my code layout (putting TextView in HorizontalScrollView tag not works scrolling, also with a click):
<LinearLayout
android:id="@+id/info_playing_song"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.82"
android:orientation="vertical">
<HorizontalScrollView
android:id="@+id/title_scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</HorizontalScrollView >
<TextView
android:id="@+id/song_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:foregroundGravity="left"
android:text="Title Song"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary" />
UPDATE:
In my fragment I have:
public void setMediaButtons(View rootView) {
albumSongPlayngImageView = (ImageView) rootView.findViewById(R.id.album_song);
titleSongPlayngTextView = (TextView) rootView.findViewById(R.id.song_title);
titleSongPlayngTextView.setMovementMethod(new ScrollingMovementMethod());
titleSongPlayngTextView.setText(firstSong.getTitle());
titleSongPlayngTextView.setSelected(true);
Log.d(LOG_TAG, "After scroll clicked song: " + titleSongPlayngTextView.getText());
//*************** HERE the TextView value is correct***************
artistSongPlayngTextView = (TextView) rootView.findViewById(R.id.song_name_artist);
artistSongPlayngTextView.setMovementMethod(new ScrollingMovementMethod());
artistSongPlayngTextView.setSelected(true);
artistSongPlayngTextView.setText(firstSong.getArtist());
In MusicService I have:
public void playSong() {
mediaPlayer = musicPlayer.getMediaPlayer();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.reset();
Song currPlaySong = arrayOfSongs.get(currentSongPosition);
long currSong = currPlaySong.getID();
Uri trackUri = ContentUris.withAppendedId(
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
currSong);
//set the data source
try {
mediaPlayer.setDataSource(getApplicationContext(), trackUri);
songTitle = currPlaySong.getTitle();
titleSongPlayngTextView.setText(songTitle);
Log.d(LOG_TAG, "TextView value: " + titleSongPlayngTextView.getText());
//*************** HERE the TextView value is correct***************
songArtist = currPlaySong.getArtist();
artistSongPlayngTextView.setText(songArtist);
} catch (Exception e) {
Log.e("MUSIC SERVICE", "Error setting data source", e);
}
mediaPlayer.prepareAsync();
}
And finally this is my modified layout (maybe it there the problem? Another problem is that if TextView value si too large I get a very small ImageView):
<?xml version="1.0" encoding="utf-8"?>
<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">
<ListView
android:id="@+id/list_songs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/fragment_button_player" />
<LinearLayout
android:id="@+id/fragment_button_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/darker_gray"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:weightSum="1">
<ImageView
android:id="@+id/album_song"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.21"
android:src="@drawable/ic_album_black_24dp" />
<LinearLayout
android:id="@+id/info_playing_song"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.82"
android:orientation="vertical">
<TextView
android:id="@+id/song_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:foregroundGravity="left"
android:text="Title Song"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary" />
<TextView
android:id="@+id/song_name_artist"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Artist Name"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<ImageButton
android:id="@+id/prev_song"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:foregroundGravity="center_vertical|bottom|right"
android:padding="8dp"
android:src="@drawable/ic_skip_previous_black_24dp"
android:tintMode="src_in" />
<ImageButton
android:id="@+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:foregroundGravity="center_vertical|bottom|right"
android:padding="8dp"
android:src="@drawable/ic_play_arrow_black_24dp"
android:tintMode="src_in" />
<ImageButton
android:id="@+id/next_song"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:foregroundGravity="center_vertical|bottom|right"
android:padding="8dp"
android:src="@drawable/ic_skip_next_black_24dp"
android:tintMode="src_in" />
</LinearLayout>
</RelativeLayout>
Here is the screen with imageView problema, only in the first image it has the real dimension, all other are scaled for TextView value too large. I want always the same dim, the real dim, like in first image.
SOLUTION for textview value cut off see here: Scrolling TextView value are cut off