アプリで 3 つのアニメーションを使用しています。
1. TextView マーク (スクロールは継続)
2. Textview の点滅 (音楽アプリが一時停止モードの場合)
3. SeekBar プログレス スレッド (再生された曲のプログレスを表示)
アプリに何よりも効果を使用している間、アプリのUIはほとんどハングしません。すべてがUIスレッドで作業していると思います。お互いに邪魔することなく、それぞれが独立して仕事をしているように扱いたいです。
コードは以下のようなものです:
アプリの XML レイアウト:
<LinearLayout
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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@android:color/black"
android:orientation="vertical">
<TextView
android:id="@+id/songCurrentDurationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="00:00"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/songTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:ellipsize="marquee"
android:fadingEdgeLength="10dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:selectAllOnFocus="true"
android:singleLine="true"
android:textColor="@android:color/white"
android:gravity="center_horizontal"
android:textSize="30sp"
android:text="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"/>
<SeekBar
android:id="@+id/songProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-15dp"
android:layout_marginRight="-15dp"
android:layout_marginTop="15dp"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/scrubber_progress_horizontal_holo_light"
android:thumb="@drawable/scrubber_control_selector_holo"
android:indeterminate="false" />
</LinearLayout>
私のクラスコードは以下のようなものです:
public class MainActivity extends Activity {
private Animation blinking_anim;
private SeekBar songProgressBar;
private TextView songCurrentDurationLabel;
private int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
blinking_anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blinking_animation);
songProgressBar = (SeekBar)findViewById(R.id.songProgressBar);
songCurrentDurationLabel = (TextView)findViewById(R.id.songCurrentDurationLabel);
songCurrentDurationLabel.startAnimation(blinking_anim);
mHandler.post(mUpdateTimeTask);
songProgressBar.setMax(10000);
}
private final Handler mHandler = new Handler();
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
try {
Thread.sleep(100);
count = count +10;
songCurrentDurationLabel.setText(""+ count);
songProgressBar.setProgress((int)count);
System.out.println("Runnnnn.........MAIN....");
if(count>=10000){
mHandler.removeCallbacks(mUpdateTimeTask);
}else
mHandler.post(mUpdateTimeTask);
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
点滅アニメーション:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" android:repeatCount="infinite">
<alpha android:fromAlpha="4.0" android:toAlpha="0.0" android:duration="1000" android:repeatCount="infinite">
</alpha></alpha>
</set>
互いにぶら下がることなく独立して動作するようにこれらすべてを実装するための助けが必要です。