我的应用程序上有三个动画。
1. TextView Marque(滚动继续)
2.闪烁的Textview(当我的音乐应用程序处于暂停模式时)
3. SeekBar Progress线程(显示播放歌曲的进度)
当我为我的应用程序使用最重要的效果时,我的应用程序的 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>
需要帮助来实现所有这些以独立工作而不会互相挂起。