我有一個ListView,我希望當我點擊一個ListView項目時,底部的TextView會改變它的值,如果文本太大,它會自動滾動。HorizontalScrollView剪切TextView中的文本並自動滾動
1)HorizontalScrollView切斷文字,原文是「恩裏克·伊格萊西亞斯 - Bailando英尺德斯坎默·布埃諾,根特德卵」,但沒有空間,所以我只看到「恩裏克·伊格萊西亞斯 - Bailando英尺 」。現在,我想用滾動我也看到「Descemer Bueno,Gente De Zona」,但沒有... TextView的值是正確的,有全名,我看到日誌...
我看到:
我看一下TextView的:
2)自動滾動不起作用,我必須點擊TextView進行滾動。
這是我的代碼佈局:
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);
這是我的代碼佈局(把TextView的在HorizontalScrollView標籤沒有作品滾動,還帶有點擊):
<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:
在我的片段中我有:
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());
在MusicService我:
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();
}
最後,這是我修改的佈局(也許有問題嗎?另一個問題是,如果TextView的累計值Si太大,我得到一個非常小的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>
這裏是ImageView的problema屏幕,只有在它具有真正的維度的第一圖像,其他所有被縮放爲TextView值太大。我總是想要像第一幅圖像一樣暗淡,真實的暗淡。
解決方案爲TextView的價值切斷在這裏看到:Scrolling TextView value are cut off
請不要更新您的問題,以包括從答案中取得的調整,從而產生一個新問題。可以添加輔助原始問題的其他信息。請看這裏http://meta.stackoverflow.com/questions/290297/how-much-change-to-the-question-is-too-much –
好的,謝謝,我在這裏寫了另一個問題:http:// stackoverflow .com/questions/33570512/scrolling-textview-value-are-cut-off – Hazlo8