How to make seekbar like this

回眸只為那壹抹淺笑 提交于 2019-12-11 01:20:05

问题


I want to apply effect to seekbar as shown below:

Download it...

What I have tried is as below.The complete code is below just try and let me know if you will get the effect like below.

MainActivity.java

public class MainActivity extends Activity 
{

 private static int myProgress=0;
 private SeekBar seekBar;
 private int progressStatus=0;
 private Handler myHandler=new Handler();

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.h_processbar);

}

public void beginYourTask(View view)
{

    myProgress=0;
    seekBar= (SeekBar)findViewById(R.id.seekBar);
    seekBar.setMax(100);

    new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            while(progressStatus<100)
            {
                progressStatus=performTask();
                myHandler.post(new Runnable()
                {
                public void run() {
                seekBar.setProgress(progressStatus);
                }
                });

            }
            myHandler.post(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                   Toast.makeText(getBaseContext(),"Task Completed",Toast.LENGTH_LONG).show();
                   progressStatus=0; 
                   myProgress=0;

                }
            });

        }
        private int performTask()
        {
            try {
                //---Do some task---
                Thread.sleep(100);
                } catch (InterruptedException e)
                {
                e.printStackTrace();
                }
                return ++myProgress;    
        }
    }).start();
   }

 }

progress_horizontal_green.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>
        <corners android:radius="5dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#ff54e854"
                    android:centerColor="#ff004900"

                    android:endColor="#ff54e854"
                    android:angle="90"
            />
        </shape>
    </clip>
 </item>

 </layer-list>

h_processbar.xml

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="beginYourTask"
    android:text="Start Task" 
    android:textColor="#ffffff"
    android:layout_margin="10dp"/>
 <LinearLayout 
   android:layout_width="290dp"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:layout_marginTop="30dp"
   >

        <SeekBar
            android:id="@+id/seekBar"
            android:max="100" 
            android:progress="60"
            android:layout_width="260dp"
            android:layout_height="wrap_content"
            android:thumb="@drawable/down_arrow_new"
            android:progressDrawable="@drawable/progress_horizontal_green"
            android:layout_margin="20dp"
            />

</LinearLayout>

down_arrow_new.png is here

Download it...

As shown in figure LHS(left hand side) it starts from dark green color and as progress goes forward it looks like the combination of light green shades with blur effect.

and blur effect makes this awesome.

How can i achieve this?Any idea?

Any help will be appreciated.

Thank you.

来源:https://stackoverflow.com/questions/16463841/how-to-make-seekbar-like-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!