zoukankan      html  css  js  c++  java
  • 2021.3.7 Android图像视图

    一、今日学习内容

       

    ImageView:

     

    1.src属性和background属性的区别:

    在API文档中我们发现ImageView有两个可以设置图片的属性,分别是:src和background

    常识:

    ①background通常指的都是背景,而src指的是内容!!

    ②当使用src填入图片时,是按照图片大小直接填充,并不会进行拉伸

    而使用background填入图片,则是会根据ImageView给定的宽度来进行拉伸

    1)写代码验证区别:

    写个简单的布局测试下:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        xmlns:tools="http://schemas.android.com/tools"  
        android:id="@+id/LinearLayout1"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:orientation="vertical"  
        tools:context="com.jay.example.imageviewdemo.MainActivity" >  
      
        <ImageView  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:background="@drawable/pen" />  
      
        <ImageView  
            android:layout_width="200dp"  
            android:layout_height="wrap_content"  
            android:background="@drawable/pen" />  
      
        <ImageView  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:src="@drawable/pen" />  
      
        <ImageView  
            android:layout_width="200dp"  
            android:layout_height="wrap_content"  
            android:src="@drawable/pen" />  
      
    </LinearLayout>

    效果图如下:

    结果分析:

    宽高都是wrap_content那就一样,是原图大小,但是,当我们固定了宽或者高的话, 差别就显而易见了,blackground完全填充了整个ImageView,而src依旧是那么大, 而且他居中了哦,这就涉及到了ImageView的另一个属性scaleType了! 另外还有一点,这里我们说了只设置width或者height哦!加入我们同时设置了 width和height的话,blackground依旧填充,但是,src的大小可能发生改变哦! 比如,我们测试下下面这段代码:

    <ImageView  
            android:layout_width="100dp"  
            android:layout_height="50dp"  
            android:src="@drawable/pen" />

    运行效果图:

    二、遇到的问题

       没有遇到什么问题

    三、明日计划

      学习视图

  • 相关阅读:
    关于UITapGestureRecognizer的一些问题
    自定义导航栏返回按钮
    mousewheel滚轮事件 浏览器的写法
    Apache日志不记录图片文件设置方法和来源日志的配置
    redis持久化配置
    haproxy实现负载均衡
    Keepalived高可用软件的安装与配置
    Sublime text2用户自定义配置
    判断各版本的最简写法
    Ubuntu防火墙 UFW 设置
  • 原文地址:https://www.cnblogs.com/wmdww/p/14903512.html
Copyright © 2011-2022 走看看