我需要在手指图标从左向右移动后立即更改背景按钮的颜色。在这里,我将屏幕短。Finger图标移动顺利,但我也需要更改背景按钮颜色。请任何一个帮助。thanx
屏幕快照
Outputhere是我的ANS,这有点印度杂物,但它充分满足了我的要求。main_overlay.xml
<?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:orientation="vertical" >
</RelativeLayout>
Overlay_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overlayLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progBar1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/btn1"
android:layout_marginBottom="100dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:background="@android:color/transparent"
android:backgroundTint="#FFA500"
android:indeterminateTint="#fddc00"
android:visibility="visible" />
<TextView
android:id="@+id/tvtitle"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="100dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:background="@android:color/transparent"
android:gravity="center"
android:text="GO Online"
android:textColor="#000"
android:visibility="visible" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="100dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:src="@drawable/finger"
android:visibility="visible" />
</RelativeLayout>
叠加
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
public class OverLayActivity extends Activity {
private ProgressBar progBar;
private int mProgressStatus = 0;
ThreadHelper t1;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main_overlay);
// for overlay screen
showOverLay();
}
TranslateAnimation animation;
@SuppressLint("NewApi")
private void showOverLay() {
final Dialog dialog = new Dialog(OverLayActivity.this,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.overlay_view);
RelativeLayout layout = (RelativeLayout) dialog
.findViewById(R.id.overlayLayout);
ImageView iv_finger = (ImageView) dialog.findViewById(R.id.imageView2);
progBar = (ProgressBar) dialog.findViewById(R.id.progBar1);
progBar.setProgressDrawable(OverLayActivity.this
.getDrawable(R.drawable.my_progress));
t1 = new ThreadHelper();
t1.start();
animation = new TranslateAnimation(0.0f, 700.0f, 0.0f, 0.0f);
yFrom,yTo)
animation.setDuration(2400); // animation duration
animation.setRepeatCount(animation.INFINITE); // animation repeat count
animation.setRepeatMode(1); // repeat animation (left to right, right to
// left )
// animation.setFillAfter(true);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.v("animateBetweenColors", "rep");
// for starting again with finger icon same time
mProgressStatus = 0;
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.v("animateBetweenColors", "end");
}
});
iv_finger.startAnimation(animation);
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
// to stop running thread
t1.stopThread();
}
});
dialog.show();
}
public synchronized void stopThread(Thread theThread) {
if (theThread != null) {
theThread = null;
animation.cancel();
Log.v("thradstop_____", "" + t1.isAlive());
}
}
public class ThreadHelper extends Thread {
public synchronized void stopThread() {
if (t1 != null) {
// to stop progressbar
mProgressStatus = 101;
t1 = null;
}
}
public void run() {
while (mProgressStatus < 100) {
// to match the speed of finger icon and progressbar
if (mProgressStatus < 30) {
mProgressStatus += 1;
} else if (mProgressStatus < 60) {
mProgressStatus += 2;
} else {
mProgressStatus += 1.7;
}
// Update the progress bar
progBar.setProgress(mProgressStatus);
Log.v("ProgressBarTest", "mProgressStatus:" + mProgressStatus);
if (mProgressStatus == 80) {
mProgressStatus = 0;
progBar.setProgress(0);
Log.v("ProgressBarTest", "sunil" + mProgressStatus);
}
try {
// Display progress slowly
Log.v("ProgressBarTest", "thread");
Thread.sleep(35);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
将my_progress.xml放在可绘制的文件夹中
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<shape>
<!-- radius background of progressbar -->
<gradient
android:angle="270"
android:centerColor="#fddc00"
android:centerY="0.75"
android:endColor="#fddc00"
android:startColor="#fddc00" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape><corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#FFA500"
android:centerY="0.75"
android:endColor="#FFA500"
android:startColor="#FFA500" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<!-- radius of secundary progress -->
<gradient
android:angle="270"
android:centerColor="#FFA500"
android:centerY="0.75"
android:endColor="#FFA500"
android:startColor="#FFA500" />
</shape>
</clip>
</item>
</layer-list>