2

我想将效果应用于搜索栏,如下所示:

下载它...

水平进度图片

我尝试过的如下。完整的代码在下面试试,如果你会得到下面的效果,请告诉我。

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_horizo​​ntal_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在这里水平进度图片 下载它...

如图LHS(左侧)所示,它从深绿色开始,随着进展,它看起来像是浅绿色阴影模糊效果的组合。

模糊效果使这很棒。

我怎样才能做到这一点?有什么想法吗?

任何帮助将不胜感激。

谢谢你。

4

0 回答 0