UI控件--ImageView和ImageButton

图片显示样式

  • android:scaleType属性值有:center,fitXY,fitstart,fitend,centerCrop,centerInside等
  • android:src 添加图片的属性
  • 蒙版属性:android:tint=”#44ff0000”
  • 未添加蒙版
    这里写图片描述
  • 添加蒙版效果
    这里写图片描述

ImageView和ImageButton的使用基本相同,具体细节自行尝试。

通过网络上图片的网址直接显示在Image控件上
public static void sendHttpRequest(final String urls, final MyHttpCallBackListener httpCallBackListener){

            new Thread(new Runnable() {
                @Override
                public void run() {
                    HttpURLConnection conn = null;
                    try {
                        URL picUrl = null;

                        picUrl = new URL(urls);
                        Bitmap pngBM = BitmapFactory.decodeStream(picUrl.openStream());
                        httpCallBackListener.onFinish(pngBM);


                    } catch (ProtocolException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                        httpCallBackListener.onError(e);
                    } finally {
                        if (conn!=null){
                            conn.disconnect();
                        }
                    }
                }
            }).start();
        }
  • 通过这个工具类,我们可以将图片在子线程中构造成一个Bitmap对象,并将其返回,然后在image控件中进行设置就可以了
  • 这里应用了观察者模式,观察者模式参见网络编程–观察者模式

第三方包CircleImageView

  • 首先我们需要导包
    这里写图片描述
  • 然后就是和普通的ImageView一样设置就可以了
    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/pp"/>

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值