2016-01-30 4 views
-1

Я пытаюсь использовать marquee в TextView который становится текст из webservice APIs. Это мой XMLMarquee в TextView с динамическими данными андроида

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#4a4a4a"> 

    <!-- Player Header --> 
    <LinearLayout 
     android:id="@+id/player_header_bg" 
     android:layout_width="fill_parent" 
     android:layout_height="60dip" 
     android:background="@layout/bg_player_header" 
     android:layout_alignParentTop="true" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp"> 

     <!-- Song Title, here I want to use marquee --> 
     <TextView 
      android:id="@+id/songTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:singleLine="true" 
      android:ellipsize="marquee" 
      android:textColor="#ffffff" 
      android:marqueeRepeatLimit="1" 
      android:scrollHorizontally="true" 
      android:paddingLeft="15dip" 
      android:paddingRight="15dip" 
      android:selectAllOnFocus="true" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:freezesText="true"/> 

     <!-- Playlist button --> 
     <!-- <ImageButton 
      android:id="@+id/btnPlaylist" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:src="@drawable/btn_playlist" 
      android:background="@null"/> --> 
    </LinearLayout> 

    <!-- Song Thumbnail Image --> 
    <LinearLayout 
     android:id="@+id/songThumbnail" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:gravity="center" 
     android:layout_below="@id/player_header_bg"> 

    <ImageView 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/adele"/>  
    </LinearLayout> 

    <!-- Player Footer --> 
    <LinearLayout 
     android:id="@+id/player_footer_bg" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:layout_alignParentBottom="true" 
     android:background="@layout/bg_player_footer" 
     android:gravity="center"> 

     <!-- Player Buttons --> 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="center_vertical" 
      android:background="@layout/rounded_corner" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp"> 
      <!-- Previous Button --> 
      <ImageButton 
       android:id="@+id/btnPrevious" 
       android:src="@drawable/btn_previous" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null"/> 
      <!-- Backward Button --> 
      <ImageButton 
       android:id="@+id/btnBackward" 
       android:src="@drawable/btn_backward" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null"/> 
      <!-- Play Button --> 
      <ImageButton 
       android:id="@+id/btnPlay" 
       android:src="@drawable/btn_play" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null"/> 
      <!-- Forward Button --> 
      <ImageButton 
       android:id="@+id/btnForward" 
       android:src="@drawable/btn_forward" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null"/> 
      <!-- Next Button --> 
      <ImageButton 
       android:id="@+id/btnNext" 
       android:src="@drawable/btn_next" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null"/> 
     </LinearLayout> 
    </LinearLayout> 

    <!-- Progress Bar/Seek bar --> 
    <SeekBar 
      android:id="@+id/songProgressBar" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="20dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginBottom="20dp" 
      android:layout_above="@id/player_footer_bg" 
      android:thumb="@drawable/seek_handler" 
      android:progressDrawable="@drawable/seekbar_progress" 
      android:paddingLeft="17dp" 
      android:paddingRight="6dp"/> 

    <!-- Timer Display --> 
    <LinearLayout 
     android:id="@+id/timerDisplay" 
     android:layout_above="@id/songProgressBar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="20dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginBottom="10dp"> 
     <!-- Current Duration Label --> 
     <TextView 
      android:id="@+id/songCurrentDurationLabel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="left" 
      android:textColor="#eeeeee" 
      android:textStyle="bold"/> 
     <!-- Total Duration Label --> 
     <TextView 
      android:id="@+id/songTotalDurationLabel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="right" 
      android:textColor="#04cbde" 
      android:textStyle="bold"/> 
    </LinearLayout> 

    <!-- Repeat/Shuffle buttons --> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/timerDisplay" 
     android:gravity="center"> 
     <!-- Repeat Button --> 
     <ImageButton 
      android:id="@+id/btnRepeat" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/btn_repeat" 
      android:layout_marginRight="5dp" 
      android:background="@null"/> 

     <!-- Shuffle Button -->   
     <!-- <ImageButton 
      android:id="@+id/btnShuffle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/btn_shuffle" 
      android:layout_marginLeft="5dp" 
      android:background="@null"/> --> 
    </LinearLayout> 
</RelativeLayout> 

Это моя активность,

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.player); 

songTitleLabel = (TextView) findViewById(R.id.songTitle); 

GENRE = getIntent().getExtras().getString("genre"); 

     songTitleLabel.setSelected(true); 
     songTitleLabel.setEllipsize(TruncateAt.END); 
     songTitleLabel.setEllipsize(TruncateAt.MARQUEE); 
     songTitleLabel.setText(GENRE); 
     songTitleLabel.setSingleLine(true); 

Но это не работает. Пожалуйста, помогите мне узнать, чего я здесь не вижу.

+0

Можете ли вы, пожалуйста, опубликовать строку шатра, как она будет выглядеть, образец. –

+0

@RaguSwaminathan, sir, Это название выбранной песни, и я получаю ее от API. это просто название песни, например «Love Story» или «In The End» – Devraj

+0

@RaguSwaminathan, я попробовал его со строкой Static, как только я положил его в xml с помощью android: text = "Lorem Ipsum Dummy Text. Lorem Ipsum Dummy Text «....... и один раз в java, используя songTitleLabel.setText (« Локальный Ipsum Dummy Text. Lorem Ipsum Dummy Text »); но результат был таким же каждый раз – Devraj

ответ

1

Я отправил ответ за то, что я упомянул в комментарии.

Хотя код, который вы написали для реализации Marquee хорошо и правильно, мы должны вспомнить, что,

текст, который будет отображаться должно быть больше, чем длина ширина экрана в устройства или необходимо зафиксировать ширину меньше длины входящей строки, будь то статический или динамический текст.

Благодарим за внимание, @devraj.

0

Пожалуйста, попробуйте это,

Xml файл

Просто замените TextView, как это, я удалил некоторые необычные теги и это работает для меня.

<TextView 
      android:id="@+id/songTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:ellipsize="marquee" 
      android:scrollHorizontally="true" 
      android:marqueeRepeatLimit="marquee_forever" 
      android:paddingLeft="15dip" 
      android:paddingRight="15dip" 
      android:singleLine="true" 
      android:textColor="#ffffff" /> 

класс Java

package com.example.demoproject; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

    public class MainActivity extends Activity { 

     private TextView songTitleLabel; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

      songTitleLabel = (TextView) findViewById(R.id.songTitle); 
      songTitleLabel.setSelected(true); 
      songTitleLabel.setText("LOREM IPSUM DUMMY TEXT. LOREM IPSUM DUMMY TEXTLOREM IPSUM DUMMY TEXT. LOREM IPSUM DUMMY TEXTLOREM IPSUM DUMMY TEXT."); 
     } 
    } 
+0

Я использую это уже ... но не работает. вы можете увидеть в моем java-коде. – Devraj

+0

Измените это, я обновил ответ, так как вам нужно поместить только метод setSelected в остальную часть кода, который вы уже сделали в xml. –

+0

Да, я последовал за вами, как вы сказали, но результат такой же. Без изменений. Я не думаю, что он поддерживает динамические значения. – Devraj

0

Я хотел бы упомянуть о нем, как идеальный answer.I видел много сообщений относительно этого, но не нашел точный ответ на особая ситуация, когда я полностью заполняю все условие , необходимое для шатер. Я получил правильный ответ От комментария @Ragu Swaminatha. «Длина строки (вы хотите использовать в шатрах) должна быть больше ширины экрана устройства« Это идеальный ответ . Производится ли строка из API или статична.