【发布时间】:2015-11-05 15:03:24
【问题描述】:
我有一个 ListView,我希望当我单击 ListView 项目时,底部的 TextView 会更改其值,如果文本太大,它会自动滚动。
1) HorizontalScrollView 将文本截掉,原文是“Enrique Iglesias - Bailando ft. Descemer Bueno, Gente De Zona”,但是没有空格所以我只看到“Enrique伊格莱西亚斯 - Bailando ft.”。现在,我希望通过滚动看到“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" />
更新:
在我的片段中,我有:
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 问题的屏幕,仅在第一张图像中它具有实际尺寸,所有其他图像都因 TextView 值太大而缩放。我想要始终保持相同的暗淡,真正的暗淡,就像第一张图片中一样。
解决方案 for textview value cut off 请参见此处:Scrolling TextView value are cut off
【问题讨论】:
-
好的,谢谢,我在这里写了另一个问题:stackoverflow.com/questions/33570512/…
标签: android scroll horizontal-scrolling horizontalscrollview autoscroll