• Android基础控件ImageView的使用


    1、相关属性

            <!--src 设置内容-->
            <!--background 设置背景-->
            <!--alpha 设置透明度 -->
            <!--adjustViewBounds 保持原图宽高比-->
            <!--maxHeight maxWidth最大宽度和高度:adjustViewBounds为true,布局宽高为wrap_content才能生效-->
            <!--scaleType 缩放类型-->

      scaleType属性详解:

    fitXY:对图像的横向与纵向进行独立缩放,使得该图片完全适应ImageView;
    fitStart:保持纵横比缩放图片,直到较长的边与ImageView的编程相等,缩放完成后将图片放在ImageView的左上角;
    fitCenter:保持纵横比缩放图片,直到较长的边与ImageView的编程相等,缩放后放于中间;
    fitEnd:保持纵横比缩放图片,直到较长的边与ImageView的编程相等,缩放后放于右下角;
    center:保持原图的大小,显示在ImageView的中心。超过部分裁剪处理;
    centerCrop:保持横纵比缩放图片,完全覆盖ImageView;
    centerInside:保持横纵比缩放图片,直到ImageView能够完全地显示图片;
    matrix:默认值,不改变原图的大小,从ImageView的左上角开始绘制原图,超过部分作裁剪处理;

    2、简单使用

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".LoginActivity">
    
    
            <!--src 设置内容-->
            <!--background 设置背景-->
            <!--alpha 设置透明度 -->
            <!--adjustViewBounds 保持原图宽高比-->
            <!--maxHeight maxWidth最大宽度和高度:adjustViewBounds为true,布局宽高为wrap_content才能生效-->
            <!--scaleType 缩放类型-->
            <ImageView
                android:id="@+id/imageview11"
                android:layout_width="wrap_content"
                android:layout_height="200dp"
                android:src="@drawable/back"
                android:background="@color/colorPrimary"/>
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageview22"
                android:src="@drawable/back"
                android:padding="5dp"
                android:background="@color/bbutton_danger"
                android:alpha="1"
                android:adjustViewBounds="true"
                android:maxHeight="150dp"
                android:maxWidth="150dp"
                android:scaleType="fitCenter"
                />
    </LinearLayout>

    效果图

  • 相关阅读:
    html的转码玉反转码
    获取url据对路径写法
    CSS 外边距合并
    页面禁制选中元素的 背景变蓝的通用写法
    centos7.3上安装oracle11.2.4RAC
    通过ansible检查所有服务器根目录磁盘使用情况
    解决es集群启动完成后报master_not_discovered_exception(hostname有错误)
    tidb4.0执行大型sql报没有tmp目录错处理(ERROR 1105 (HY000): open /tmp/1000_tidb/MC4wLjAuMDo0MDAwLzAuMC4wLjA6MTAwODA)
    aix磁盘创建pv、lv
    aix6.1安装oracle
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/8078973.html
Copyright © 2020-2023  润新知