Android 常用控件 图片框与进度条

ScaleType的8个属性

这是效果图

这里写图片描述

这是原图小的

这里写图片描述

代码,进度条

package com.example.android_06;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private ProgressBar main_pb_pb1;
    private TextView tv_tv1;
    private int p=0;
    private MyHandler MyHandler=new MyHandler();
    private class MyHandler extends Handler{
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:
                    main_pb_pb1.setProgress(p++);
                    tv_tv1.setText(p+"%");
                    break;

            }

        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        main_pb_pb1=this.findViewById(R.id.main_pb_pb1);
        tv_tv1=this.findViewById(R.id.tv_tv1);
    }

    //弹框
    public void Myid(View view) {
        Toast.makeText(this, "xx", Toast.LENGTH_SHORT).show();
    }

    //进度条
    public void setPro(View view) {
   if(p==0){
       new MyThread().start();
   }
    }

    //子线程
    private class MyThread extends  Thread{
        @Override
        public void run() {
            super.run();
            while (true){
                try {
                    Thread.sleep(100);//抛异常
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if(p==100){
                    p=0;
                  break;
                }
                Message msg=new Message();
                msg.what=1;
                MyHandler.sendMessage(msg);


            }
        }
    }
}

activity_main.xml的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <ImageView
        android:layout_width="100dp"
        android:layout_gravity=""
        android:background="@color/colorAccent"
        android:src="@drawable/small_image"
        android:scaleType="matrix"
        android:layout_height="100dp" />
<Button
    android:layout_width="match_parent"
    android:onClick="Myid"
    android:layout_height="wrap_content"
     />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="30dp">
     <TextView
         android:id="@+id/tv_tv1"
         android:layout_width="30dp"
         android:layout_height="match_parent" />
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/main_pb_pb1"
            android:max="100" />


    </FrameLayout>
    <Button
        android:layout_width="match_parent"
        android:onClick="setPro"
        android:id="@+id/main_but_but1"
        android:layout_height="wrap_content"
        />
</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值