Horizo​​ntalScrollView切一个TextView和autoscorlling文本 [英] HorizontalScrollView cut the text in a TextView and autoscorlling

查看:368
本文介绍了Horizo​​ntalScrollView切一个TextView和autoscorlling文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView,我想,当我点击一个ListView项,底部的TextView改变其值,如果文本太大它的自动滚动。

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)Horizo​​ntalScrollView切断文字,原文是恩里克·伊格莱西亚斯 - Bailando英尺Descemer布埃诺,根特德卵的,但没有空间,所以我只看到恩里克伊格莱西亚斯 - Bailando英尺的。现在,我想,随着滚动我也看到了 Descemer布埃诺,根特德卵的,但没有......在 TextView的值是正确,还有就是满的名字,我看到日志...

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...

我看到的:

在这里输入的形象描述

我看到点击TextView的:

What I see clicking on the TextView:

在这里输入的形象描述

2)自动滚动不工作,我要对TextView的点击滚动。

2) Autoscrolling not working, I have to click on the TextView for scrolling.

这是我的code布局:

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);

这是我的code布局(将在TextView的标签Horizo​​ntalScrollView作品不滚动,还带有点击):

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" />

更新:

在我的片段,我有:

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我有:

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();
}

最后,这是我修改的布局(也许是有问题的另一个问题是,如果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的值过大。我想总是相同的暗淡,真正的暗淡,像第一张图像。

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 作为TextView的价值在这里看到:滚动的TextView值

SOLUTION for textview value cut off see here: Scrolling TextView value are cut off

在这里输入的形象描述

推荐答案

默认情况下,字幕只会滚动的onfocus。所以,如果你的setSelected为真,它将始终被聚焦,从而滚动。

By default, the marquee will only scroll onfocus. So if you setSelected as true, it will always be focused and hence scroll.

您需要的setSelected真对你的TextView,所以文本将滚动。

You need to setSelected to true on your textview, so the text will scroll.

titleSongPlayngTextView.setSelected(true);

此外,还有有没有在它的TextView滚动视图没有意义的。你并不需要使用滚动视图,但如果这样做,把TextView的在里面。

Also, there's no point having the scrollview without the textview in it. You do not need to use a scrollview, but if you do, put the textview in it.

至于它切断文字,我需要看到你的code,有您的播放器控件在TextView的。

As for it cutting off the text, I would need to see your code, as you have the player controls over the textview.

修改结果
经过信息的

你的权重之和比你的1 weightsum更大。

The sum of your weights is greater than your weightsum of 1.

您前两个子元素都大于1,你有没有包含在此图像按钮。

You first two child elements are greater than 1 and you have not included your image buttons in this.

可以不使用weightsum,在这种情况下weightsum将是总所有的权重。否则,确保您的权重高达添加到你的体重总和。另外一个监督对我而言,设置布局宽度使用重布局时,0dp。

You can not use weightsum, in which case the weightsum will be the total of all the weights. Otherwise ensure your weights add up to the to your weight sum. Also an oversight on my part, set your layout widths to 0dp when using layout weight.

<LinearLayout
    android:id="@+id/fragment_button_player"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    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"
        <TextView
            android:id="@+id/song_name_artist"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
    </LinearLayout>

    // These below are not included in your weightSum

    <ImageButton
        android:id="@+id/prev_song"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
    <ImageButton
        android:id="@+id/play_pause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
    <ImageButton
        android:id="@+id/next_song"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"            
</LinearLayout>

所以,你会是这样的:

So you would have something like this:

    <ImageView
        android:id="@+id/album_song"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_weight="0.2"
        android:foregroundGravity="center_vertical|bottom|left"
        android:src="@drawable/ic_album_black_24dp"/>

    <LinearLayout
        android:id="@+id/info_playing_song"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:orientation="vertical">

        <TextView
            android:id="@+id/song_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:foregroundGravity="left"
            android:marqueeRepeatLimit="marquee_forever"
            android:maxLines="1"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="Title Song and too much information to display in one line."
            android:textAppearance="?android:attr/textAppearanceMedium"/>

        <TextView
            android:id="@+id/song_name_artist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            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 and too much information to read in one line."
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

    <ImageButton
        android:id="@+id/prev_song"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_weight="0.1"
        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="0dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_weight="0.1"
        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="0dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_weight="0.1"
        android:foregroundGravity="center_vertical|bottom|right"
        android:padding="8dp"
        android:src="@drawable/ic_skip_next_black_24dp"
        android:tintMode="src_in"/>

</LinearLayout>

我测试过这一点,它的工作原理。你可以用你的权重,以满足您的需求摇晃。

I've tested this and it works. You can jiggle with your weights to suit your needs.

这篇关于Horizo​​ntalScrollView切一个TextView和autoscorlling文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆