• 安卓app_sl4_2水平进度条与圆形进度条_与线程的启动


    安卓app_sl4_2水平进度条与圆形进度条_与线程的启动

    <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.sl4_2.MainActivity" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    
        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="42dp" />
    
        <ProgressBar
            android:id="@+id/progressBar2"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/progressBar1"
            android:layout_marginTop="28dp" />
    
    </RelativeLayout>
    package com.example.sl4_2;
    
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.ProgressBar;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
        private ProgressBar horizonP;
        private ProgressBar circleP;
        private int mProgressStatus = 0;
        private Handler mHandler;//声明一个用于处理消息的Handler类的对象
        
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            horizonP=(ProgressBar) findViewById(R.id.progressBar1);
            circleP = (ProgressBar) findViewById(R.id.progressBar2);
            mHandler=new Handler(){
                @Override
                  public void handleMessage(Message msg)
                {
                        if(msg.what==0x111)
                        {
                            horizonP.setProgress(mProgressStatus);
                            circleP.setProgress(100-mProgressStatus);
                        }
                        else
                        {
                            Toast.makeText(MainActivity.this, "耗时操作已经完成",Toast.LENGTH_SHORT).show();
                            horizonP.setVisibility(View.GONE);
                            circleP.setVisibility(View.GONE);;
                        }
            
                }
    
                };
                new Thread(new Runnable()
                {
                    public void run()
                    {
                        while(true)
                        {
                            mProgressStatus=doWork();
                            Message m=new Message();
                            if(mProgressStatus<100)
                            {
                                m.what=0x111;
                                mHandler.sendMessage(m);
                            }
                            else
                            {
                                m.what=0x110;
                                mHandler.sendMessage(m);
                                break;
                            }
                        }
                    }
                    private int doWork()
                    {
                        mProgressStatus+=Math.random()*10;
                        try
                        {
                            Thread.sleep(200);
                        }
                        catch(InterruptedException e)
                        {
                            e.printStackTrace();
                        }
                        return mProgressStatus;
                    }
                    
                }).start();
        }
                    
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    }
  • 相关阅读:
    Anaconda+Tensorflow环境安装与配置(转载)
    Win10 Anaconda下TensorFlow-GPU环境搭建详细教程(包含CUDA+cuDNN安装过程)(转载)
    设计模式之工厂方法模式VS简单工厂方法模式
    WPF之外观模式
    WPF之小动画三
    WPF之小动画二
    WPF之小动画一
    WPF之Behavior
    WPF之拖动项滚动条自滚动(当拖动项到达高度的边界时候滚动条自己可以上下滚动)
    WPF之给使用了模板的MenuItem添加快捷操作
  • 原文地址:https://www.cnblogs.com/txwtech/p/15942269.html
Copyright © 2020-2023  润新知