动态字幕的文本

是否可以将列表视图的java编码中的文本添加到Android中的选框滚动。 如果是的话,请告诉我怎么做?

如果需要,我将发布使用的代码。 这是用于listview的XML,如下所示

       

listview的java类如下

 public class Audiovediolist extends Activity implements OnItemClickListener { private ListView audioList; private Intent frmHome; private ArrayList<HashMap> dataList; private HashMap map; private HashMap data; private int Screen_Id; private AdView adView; String name; String mSign[] = { "Aries-Mesam", "Taurus-Vrushabham", "Gemini-Midhunam", "Cancer-Karkatakam", "Leo-Simham", "Virgo-Kanya", "Libra-Tula", "Scorpio-Vruchikam", "Sagittarius-Dhanussu", "Capricorn-Makaram", "Aquarius-Kumbham", "Pisces-Meenam" }; Integer mImages[] = { R.drawable.meshamu, R.drawable.vrushabhamu, R.drawable.medhunam, R.drawable.karkatakam, R.drawable.simham, R.drawable.kanya, R.drawable.tula, R.drawable.vruchikam, R.drawable.dhanussu, R.drawable.makaramu, R.drawable.kumbhamu, R.drawable.meenamu }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_RIGHT_ICON); setContentView(R.layout.list); frmHome = getIntent(); getIntentValues(); initUI(); setUI(); uiListener(); } private void initUI() { audioList = (ListView) findViewById(R.id.audiolist_listView); dataList = new ArrayList<HashMap>(); adView = new AdView(this, AdSize.SMART_BANNER, "a150b89c23af3b2"); LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1); layout.setGravity(Gravity.TOP); layout.addView(adView); adView.loadAd(new AdRequest()); } private void uiListener() { audioList.setOnItemClickListener(this); } private void getIntentValues() { String id = frmHome.getStringExtra("Activity_Id"); Screen_Id = Integer.parseInt(id); if (Screen_Id == 1) { getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.audioo); this.setTitle(getResources().getString(R.string.audio)); this.setTitleColor(getResources().getColor(R.color.Beige)); } else { this.setTitle(getResources().getString(R.string.video)); this.setTitleColor(getResources().getColor(R.color.Beige)); getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.videoo); } } private void setAdapter() { SimpleAdapter adapter = new SimpleAdapter(this, dataList, R.layout.list_row, new String[] { "Image", "text" }, new int[] { R.id.audiolist_row_img, R.id.audiolist_row_tv }); audioList.setAdapter(adapter); } private void setUI() { for (int a = 0; a <= 11; a++) { map = new HashMap(); map.put("Image", "" + mImages[a]); map.put("text", mSign[a]); dataList.add(map); map = null; } } @Override protected void onStart() { super.onStart(); setAdapter(); } @Override public void onBackPressed() { super.onBackPressed(); System.gc(); } @Override protected void onDestroy() { super.onDestroy(); adView.destroy(); } /* * private class NextTask extends AsyncTask { ProgressDialog * progressDailog = new ProgressDialog(Audiovediolist.this); * * @Override protected void onPreExecute() { super.onPreExecute(); * progressDailog.setTitle("Please Wait"); * progressDailog.setMessage("URL Data Loading ..."); * progressDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER); * progressDailog.setCancelable(true); progressDailog.show(); } * * @SuppressWarnings("static-access") * * @Override protected Void doInBackground(Void... params) { return null; } * * @Override protected void onPostExecute(Void result) { * progressDailog.dismiss(); } } */ @Override public void onItemClick(AdapterView parent, View view, int position, long id) { data = dataList.get(position); //FinalConstants.AUDIO_VIDEO = "list"; try { NetWorkCheck netWork = new NetWorkCheck(); if (netWork.isNetWorkConnection(this)) { if (Screen_Id == 1) { // new NextTask().execute(); Intent audioInt=new Intent(getApplicationContext(),AudioView.class); audioInt.setType(data.get("text")); startActivity(audioInt); } else if (Screen_Id == 2) { Intent vedioInt = new Intent(this, VideoPlayActivity.class); vedioInt.setType(data.get("text")); startActivity(vedioInt); } } else { netWork.alert(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, "Problem while ListItemClick", Toast.LENGTH_SHORT).show(); } } } 

我需要选择滚动的文本的音频播放器代码如下

 public class AudioView extends Activity implements OnClickListener { private MediaPlayer mMediaPlayer; private ImageView mPlay; private ImageView mPause; private ImageView mBack; private ImageView mFar; private ProgressBar myProgressBar; private boolean boolFlag = false; private boolean isPausedInCall = false; private String url; private TelephonyManager mTelephoneMgr; private NotificationManager mNotificationManager; private int SIMPLE_NOTFICATION_ID; private TextView tv; // private boolean serviceRunning; Notification notifyDetails; private AdView adView; @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.marquee); Toast.makeText(this,"please wait.........",Toast.LENGTH_LONG).show(); url=getIntent().getType(); initUI(); uiListener(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notifyDetails = new Notification(R.drawable.mulug_icon, url, System.currentTimeMillis()); mTelephoneMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mTelephoneMgr != null) { mTelephoneMgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } /*if(FinalConstants.AUDIO_VIDEO=="listitem"){ LoginProgress task = new LoginProgress(); task.applicationContext = AudioView.this; task.execute(); }*/ } private void initUI() { tv = (TextView) findViewById(R.id.text); mBack = (ImageView) findViewById(R.id.back); mPlay = (ImageView) findViewById(R.id.play); mPause = (ImageView) findViewById(R.id.pause); mFar = (ImageView) findViewById(R.id.fwd); myProgressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal); myProgressBar.setProgressDrawable(getResources().getDrawable( R.drawable.green_progress)); myProgressBar.setProgress(0); adView = new AdView(this, AdSize.BANNER, "a150b89c23af3b2"); LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1); layout.setGravity(Gravity.TOP); layout.addView(adView); adView.loadAd(new AdRequest()); tv.setText(url + "more Deails Click on www.mulugu.com"); tv.setSelected(true); } private void uiListener() { mPlay.setOnClickListener(this); mPlay.setOnClickListener(this); mPause.setOnClickListener(this); mPause.setVisibility(android.view.View.INVISIBLE); mBack.setOnClickListener(this); mFar.setOnClickListener(this); } private Thread myThread = new Thread() { public void run() { while (mMediaPlayer.getCurrentPosition()  10000 ? dur - 5000 : 0); mMediaPlayer.seekTo(pos); break; case R.id.fwd: int curpos = mMediaPlayer.getCurrentPosition(); int dur2 = mMediaPlayer.getDuration(); int pos2 = (curpos + 5000 > dur2 ? dur2 : curpos + 5000); mMediaPlayer.seekTo(pos2); break; } } @SuppressWarnings("deprecation") private void notificationShow() { Context context = getApplicationContext(); CharSequence contentTitle = "Mulugu Running"; CharSequence contentText = url + " Weekly Predictions"; Intent notifyIntent = new Intent(AudioView.this, AudioView.class); PendingIntent intent = PendingIntent.getActivity(AudioView.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP); notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); } private void changePlayerIcons(boolean b) { if (b) { mPlay.setVisibility(android.view.View.INVISIBLE); mPause.setVisibility(android.view.View.VISIBLE); } else { mPlay.setVisibility(android.view.View.VISIBLE); mPause.setVisibility(android.view.View.INVISIBLE); } } /*public class LoginProgress extends AsyncTask { private ProgressDialog dialog; protected Context applicationContext; @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); this.dialog.dismiss(); } @Override protected void onPreExecute() { this.dialog = ProgressDialog.show(applicationContext, "Data Loading", "Loading .....", true); } @Override protected Void doInBackground(Void... params) { LoadUrl(); return null; } private void LoadUrl() { mMediaPlayer = new MediaPlayer(); mMediaPlayer.reset(); try { mMediaPlayer.setDataSource(AudioView.this,Uri.parse(FinalConstants.URL + "mobile-audio/" + getIntent().getType()+ ".mp3")); mMediaPlayer.setLooping(false); // Set looping mMediaPlayer.prepare(); myProgressBar.setMax(mMediaPlayer.getDuration()); } catch (Exception e) { e.printStackTrace(); } } }*/ } 

如果您需要移动文本,这可能会有所帮助:

http://developer.android.com/guide/topics/resources/animation-resource.html#translate-element

如果你有一个文本太大的TextView,你想让它移动所以人们可以读取整个东西,试试.xml文件中的android:ellipsize="marquee" ,或者在Java代码中: textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

如果android库不够,你可以随时通过编码使用java。 创建一个线程类,用于获取视图并随时更改条件。 您可以创建调用该类的意图。

您可以使用TextSwitcher并在其上应用animation。

试试以下代码:

 public class TextSwitcherActivity extends Activity implements ViewSwitcher.ViewFactory, View.OnClickListener { private TextSwitcher m_switcher; private Button m_nextButton; private int m_counter = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); m_switcher = (TextSwitcher) findViewById(R.id.tsSwitcher); m_switcher.setFactory(this); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); m_switcher.setInAnimation(in); m_switcher.setOutAnimation(out); m_nextButton = (Button) findViewById(R.id.next); m_nextButton.setOnClickListener(this); updateCounter(); } /** * Update counter value */ public void onClick(View v) { m_counter++; updateCounter(); } /** * Set text on textswitcher */ private void updateCounter() { m_switcher.setText(String.valueOf(m_counter)); } public View makeView() { TextView t = new TextView(this); t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); t.setTextSize(36); return t; } 

您可以定义自己的animation以获得选框效果。

这是一个例子

   

在java中(如果您正在使用Listview并绑定适配器,那么当您对Layout及其视图组件进行充气时,在getview中,将所选标志设置为true到TextView。)

 tv = (TextView) this.findViewById(R.id.tv); tv.setSelected(true);