Android按钮的背景颜色在手指图标移动时从左到右变化不大

Android按钮的背景颜色在手指图标移动时从左到右变化不大,android,Android,我需要改变背景按钮的颜色,只要手指图标从左向右移动。这里我附加屏幕短。手指图标移动平稳,但我需要改变背景按钮的颜色以及。请任何人帮忙。 塔克斯 这是我的ans,有点印度特色,但它完全满足了我的要求。 main_overlay.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:la

我需要改变背景按钮的颜色,只要手指图标从左向右移动。这里我附加屏幕短。手指图标移动平稳,但我需要改变背景按钮的颜色以及。请任何人帮忙。 塔克斯

这是我的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>

OverLayActivity.java

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

    }
   }
}
导入android.annotation.SuppressLint;
导入android.app.Activity;
导入android.app.Dialog;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.view.Window;
导入android.view.animation.animation;
导入android.view.animation.animation.AnimationListener;
导入android.view.animation.TranslateAnimation;
导入android.widget.ImageView;
导入android.widget.ProgressBar;
导入android.widget.RelativeLayout;
公共类覆盖活动扩展了活动{
私人ProgressBar progBar;
private int mProgressStatus=0;
ThreadHelper-t1;
@SuppressLint(“新API”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(右布局、主覆盖);
//用于覆盖屏幕
showOverLay();
}
翻译动画;
@SuppressLint(“新API”)
私有void showOverLay(){
最终对话框=新对话框(OverlyActivity.this,
android.R.style.Theme(半透明的NoTitleBar);
对话框.setContentView(R.layout.overlay_视图);
RelativeLayout布局=(RelativeLayout)对话框
.findviewbyd(R.id.overlylayout);
ImageView iv_finger=(ImageView)dialog.findViewById(R.id.imageView2);
progBar=(ProgressBar)dialog.findViewById(R.id.progBar1);
progBar.setProgressDrawable(OverlyActivity.this
.getDrawable(R.drawable.my_progress));
t1=新的ThreadHelper();
t1.start();
动画=新的TranslateAnimation(0.0f、700.0f、0.0f、0.0f);
yFrom,yTo)
animation.setDuration(2400);//动画持续时间
animation.setRepeatCount(animation.INFINITE);//动画重复计数
animation.setRepeatMode(1);//重复动画(从左到右,从右到右
//(左)
//animation.setFillAfter(true);
setAnimationListener(新的AnimationListener(){
@凌驾
onAnimationStart上的公共无效(动画){
//TODO自动生成的方法存根
}
@凌驾
onAnimationRepeat上的公共无效(动画){
//TODO自动生成的方法存根
Log.v(“AnimateBeweenColors”、“rep”);
//用于同时使用手指图标重新启动
mProgressStatus=0;
}
@凌驾
onAnimationEnd上的公共无效(动画){
//TODO自动生成的方法存根
Log.v(“动画背景颜色”、“结束”);
}
});
iv_.开始动画(动画);
layout.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
dialog.dismise();
//停止运行线程
t1.stopThread();
}
});
dialog.show();
}
公共同步的void stopThread(线程线程){
如果(theThread!=null){
线程=null;
动画。取消();
Log.v(“thradstop”和“+t1.isAlive());
}
}
公共类ThreadHelper扩展线程{
公共同步的void stopThread(){
如果(t1!=null){
//停止前进吧
mProgressStatus=101;
t1=null;
}
}
公开募捐{
而(mProgressStatus<100){
//匹配手指图标和进度条的速度
如果(mProgressStatus<30){
mProgressStatus+=1;
}否则如果(mProgressStatus<60){
mProgressStatus+=2;
}否则{
mProgressStatus+=1.7;
}
//更新进度条
progBar.setProgress(mProgressStatus);
Log.v(“ProgressBarTest”、“mProgressStatus:+mProgressStatus”);
如果(mProgressStatus==80){
mProgressStatus=0;
progBar.setProgress(0);
Log.v(“ProgressBarTest”、“sunil”+mProgressStatus);
}
试一试{
//缓慢显示进度
Log.v(“ProgressBarTest”、“thread”);
睡眠(35);
}捕捉(中断异常e){
e、 printStackTrace();
}
}
}
}
}
将my_progress.xml放入drawable文件夹

   <?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>