ImageView图像视图

本文详细介绍了Android中ImageView的src和background属性的区别。src用于设置图像内容,保持原尺寸显示,而background会根据ImageView大小拉伸图片。通过示例XML展示了如何设置ImageView的属性,包括限制图片大小、调整图片位置和应用颜色过滤。同时,还提及了通过android:rotation属性实现图片旋转的方法。
摘要由CSDN通过智能技术生成

  在API文档中,我们发现ImageView有两个可以设置图片的属性,分别是srcbackground。它们之间的区别如下:

  • background通常指的都是背景,而src指的是内容。
  • 当使用src填入图片时,是按照图片大小直接填充,并不会进行拉伸;而使用background填入图片,则会根据ImageView给定的宽度来进行拉伸。

  XML文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <!-- 原尺寸显示的图像 -->
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:src="@mipmap/apple" />
    <!-- 限制最大宽度和高度 -->
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:adjustViewBounds="true"
        android:maxHeight="90dp"
        android:maxWidth="90dp"
        android:src="@mipmap/apple" />
    <!-- 缩放图片后将其放在右下角 -->
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_margin="5dp"
        android:scaleType="fitEnd"
        android:src="@mipmap/apple" />
    <!-- 为图片进行着色 -->
    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:src="@mipmap/apple"
        android:tint="#77ff0000" />
</LinearLayout>

在这里插入图片描述
  对于ImageView的旋转,可以通过在xml中设置ImageView的属性来实现:

android:rotation="90"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值