5

リストビューのJavaコーディングからAndroidのマーキースクロールにテキストを追加することは可能ですか?はいの場合、方法を教えていただけますか?

必要に応じて、使用したコードを投稿します。これは、使用されたリストビューのXMLは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
     <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    </LinearLayout>
    <ListView
        android:id="@+id/audiolist_listView"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        android:background="@drawable/backgroundimg"
        android:divider="@drawable/gradient"
        android:dividerHeight="1dp"
        android:scrollbars="vertical" >
    </ListView>

</LinearLayout>

リストビューのJavaクラスは次のとおりです。

public class Audiovediolist extends Activity implements OnItemClickListener {
    private ListView audioList;
    private Intent frmHome;
    private ArrayList<HashMap<String, String>> dataList;
    private HashMap<String, String> map;
    private HashMap<String, String> 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<String, String>>();
        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<String, String>();
            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<Void,Void,Void> { 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() < mMediaPlayer
                    .getDuration()) {
                try {
                    myProgressBar
                            .setProgress(mMediaPlayer.getCurrentPosition());
                } catch (Throwable t) {
                }
            }
        }
    };



    @Override
    protected void onStart() {
        super.onStart();
        this.setProgressBarIndeterminateVisibility(true);
        try {
            if (boolFlag == false) {
                System.out.println(FinalConstants.URL + "mobile-audio/" + url+ ".mp3");
                mMediaPlayer = MediaPlayer.create(
                        this,
                        Uri.parse(FinalConstants.URL + "mobile-audio/" + url
                                + ".mp3"));
            }
            myProgressBar.setMax(mMediaPlayer.getDuration());
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "Data not available",
                    Toast.LENGTH_SHORT).show();
            Log.e("ERRORS", "Data Not Exist in that Url...");
            super.onBackPressed();
            e.printStackTrace();
        }
    }

    @SuppressLint("NewApi")
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        mMediaPlayer.stop();
        // myThread.stop();
        mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
        System.gc();
    }

    @Override
    protected void onDestroy() {
        adView.destroy();
        super.onDestroy();
        System.gc();
    }



    public PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_RINGING) {
                System.out.println("ringing state");
                if (mMediaPlayer != null) {
                    pauseMedia();
                    isPausedInCall = true;
                }
                notificationShow();
            }
            if (state == TelephonyManager.CALL_STATE_IDLE) {
                System.out.println("callState Idle");
                if (mMediaPlayer != null) {
                    if (isPausedInCall) {
                        isPausedInCall = false;
                        playMedia();
                    }
                }
            }
            if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    };

    private void pauseMedia() {
        mMediaPlayer.pause();
        changePlayerIcons(false);
    }

    private void playMedia() {
        mMediaPlayer.start();
        changePlayerIcons(true);
    }
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.play:
            if (!boolFlag) {
                try {
                    notificationShow();
                     mMediaPlayer.setLooping(false);
                     mMediaPlayer.prepareAsync();
                } catch (Exception e) {
                    Toast.makeText(this, "preparing", Toast.LENGTH_SHORT)
                            .show();
                }
                boolFlag = true;
                mMediaPlayer.start();
                myThread.start();
            } else {
                notificationShow();
                mMediaPlayer.getCurrentPosition();
                mMediaPlayer.start();
            }
            changePlayerIcons(true);
            myProgressBar.setProgress(mMediaPlayer.getCurrentPosition());
            mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer arg0) {
                    changePlayerIcons(false);
                    myProgressBar.setProgress(0);
                    onStart();
                }
            });
            mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                }
            });
            break;
        case R.id.pause:
            mMediaPlayer.pause();
            mPlay.setVisibility(android.view.View.VISIBLE);
            mPause.setVisibility(android.view.View.INVISIBLE);
            break;
        case R.id.back:
            int dur = mMediaPlayer.getCurrentPosition();
            int pos = (dur > 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<Void, Void, Void> {

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

5 に答える 5

3

テキストを移動する必要がある場合は、おそらくこれが役立ちます。

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

大きすぎるテキストを含む TextView があり、人々が全体を読めるように移動させたい場合android:ellipsize="marquee"は、.xml ファイルまたは Java コードで 試してください。textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

于 2012-12-19T16:37:56.683 に答える
1

Android ライブラリが十分でない場合は、コーディングを介していつでも Java を使用できます。ビューを取得し、時間の経過とともに条件を変更するスレッド クラスを作成します。そのクラスを呼び出すインテントを作成できます。

于 2012-12-20T07:07:31.973 に答える
1

TextSwitcherを使用して、アニメーションを適用できます。

以下のコードを試してください:

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

独自のアニメーションを定義して、マーキー効果を得ることができます。

于 2012-12-21T09:56:14.460 に答える
0

これが例です

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
    android:id="@+id/mywidget"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:lines="1"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:textColor="#ff4500"
    android:text="Simple application that shows how to use marquee, with a long text" />

Javaの場合(Listviewを使用してアダプターをバインドしている場合、getviewでレイアウトとそのビューコンポーネントを拡張するときに、選択したフラグをTextViewに対してtrueに設定します。)

tv = (TextView) this.findViewById(R.id.tv);  
    tv.setSelected(true);  
于 2012-12-24T13:50:41.103 に答える