ScaleType的8个属性
![这是效果图](https://i-blog.csdnimg.cn/blog_migrate/cdfbdb79dd65e3bf3e65a187ca71133d.jpeg)
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/d058881d1fb711272b4d746a4f8611a0.png)
![这是原图小的](https://i-blog.csdnimg.cn/blog_migrate/6f5087ab4cc26ec987a7fc9d0600bb0c.jpeg)
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/34dbc07787f0eec334edcd450b3e2aab.png)
代码,进度条
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>