android控件ImageView

一、ImageVIew中的scaleType属性

这个属性是用来控制我们的图片怎样缩扩或者移动来匹配我们和ImageView本身设置的大小

http://www.cnblogs.com/xiaoluo501395377/p/3390909.html

要想让 scaleType="center" 起作用,图片必须放在 drawable/hdpi 目录中

二、ImageView的background和src属性

背景就是在后面的东西,不会前来干扰你前面的 src

三、关于drawable中的shape标签

corners、gradient、padding、size、solid、stroke

  1、corners:

          <corners    //定义圆角  
              android:radius="dimension"      //全部的圆角半径  
              android:topLeftRadius="dimension"   //左上角的圆角半径  
              android:topRightRadius="dimension"  //右上角的圆角半径  
              android:bottomLeftRadius="dimension"    //左下角的圆角半径  
              android:bottomRightRadius="dimension" />    //右下角的圆角半径  

           Corners标签是用来字义圆角的,其中radius与其它四个并不能共同使用。

          android:radius:定义四个角的的圆角半径

  2、solid:

      用来指定内部填充颜色

        <solid  android:color="color" />

  3、gradient

      gradient用以定义渐变色,可以定义两色渐变和三色渐变,及渐变样式

      <gradient 
          android:type=["linear" | "radial" | "sweep"]    //共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变  
          android:angle="integer"     //渐变角度,必须为45的倍数,0为从左到右,90为从上到下  
          android:centerX="float"     //渐变中心X的相当位置,范围为0~1  
          android:centerY="float"     //渐变中心Y的相当位置,范围为0~1  
          android:startColor="color"   //渐变开始点的颜色  
          android:centerColor="color"  //渐变中间点的颜色,在开始与结束点之间  
          android:endColor="color"    //渐变结束点的颜色  
          android:gradientRadius="float"  //渐变的半径,只有当渐变类型为radial时才能使用  
          android:useLevel=["true" | "false"] />  //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果

  4、stroke

    描边属性

    <stroke       
        android:width="dimension"   //描边的宽度  
        android:color="color"   //描边的颜色  
        // 以下两个属性设置虚线  
        android:dashWidth="dimension"   //虚线的宽度,值为0时是实线  
        android:dashGap="dimension" />      //虚线的间隔 

  5、padding、size

    定义内部的边距和图片的大小

 

四、ImageView如何获得网络资源图片

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //图片资源
        String url = "http://s16.sinaimg.cn/orignal/89429f6dhb99b4903ebcf&690";
        //得到可用的图片
        Bitmap bitmap = getHttpBitmap(url);
        imageView = (ImageView)this.findViewById(R.id.imageViewId);
        //显示
        imageView.setImageBitmap(bitmap);
        
    }
    /**
     * 获取网落图片资源
     * @param url
     * @return
     */
    public static Bitmap getHttpBitmap(String url){
        URL myFileURL;
        Bitmap bitmap=null;
        try{
            myFileURL = new URL(url);
            //获得连接
            HttpURLConnection conn=(HttpURLConnection)myFileURL.openConnection();
            //设置超时时间为6000毫秒,conn.setConnectionTiem(0);表示没有时间限制
            conn.setConnectTimeout(6000);
            //连接设置获得数据流
            conn.setDoInput(true);
            //不使用缓存
            conn.setUseCaches(false);
            //这句可有可无,没有影响
            //conn.connect();
            //得到数据流
            InputStream is = conn.getInputStream();
            //解析得到图片
            bitmap = BitmapFactory.decodeStream(is);
            //关闭数据流
            is.close();
        }catch(Exception e){
            e.printStackTrace();
        }
         
        return bitmap;
         
    }

 

posted @ 2017-09-04 11:45  迈阿密大腮帮  阅读(140)  评论(0编辑  收藏  举报