笔者今天分享出自己常用的实现方式 —— 继承ImageView重写onDraw方法,手动裁剪。绘制完成后,使用方式就和普通的ImageView无异。 效果图: ?
* @attr ref android.R.styleable#ImageView_src * @attr ref android.R.styleable#ImageView_maxWidth...* @attr ref android.R.styleable#ImageView_maxHeight * @attr ref android.R.styleable#ImageView_tint...* @attr ref android.R.styleable#ImageView_scaleType * @attr ref android.R.styleable#ImageView_cropToPadding...dimen/sp_16" --- 三、adjustViewBounds 前提:1.保证layout_width、layout_height为wrap_content 2.设置了maxHeight、maxWidth...:maxHeight="50dp" android:maxWidth="50dp" android:adjustViewBounds="true" --- 四、tint覆盖色:最好有透明度的颜色,不然图片就全盖住了
正确答案是: android:src在设置ImageView的setAlpha(int alpha)时,起作用; android:background在设置ImageView的setAlpha(int...四、正确使用ImageView的“android:adjustViewBounds” adjustViewBounds的介绍如下: Set this to true if you want the ImageView...的最大高度,单独使用无效,需要与setAdjustViewBounds一起使用;如果想设置图片固定大小,又想保持图片宽高比,需要如下设置: 设置setAdjustViewBounds为true; 设置maxWidth...、MaxHeight; 设置设置layout_width和layout_height为wrap_content 五、正确使用ImageView的“android:scaleType” 如前所说,ImageView...:scaleType=”fitXY”,能否不设置或者设置其他属性。
, defStyle, 0); Drawable d = a.getDrawable(com.android.internal.R.styleable.ImageView_src);..., -1); setAdjustViewBounds( a.getBoolean(com.android.internal.R.styleable.ImageView_adjustViewBounds..., false)); setMaxWidth(a.getDimensionPixelSize( com.android.internal.R.styleable.ImageView_maxWidth..., Integer.MAX_VALUE)); int index = a.getInt(com.android.internal.R.styleable.ImageView_scaleType...假设想设置图片固定大小,又想保持图片宽高比,须要例如以下设置: 1) 设置setAdjustViewBounds为true; 2) 设置maxWidth、MaxHeight; 3) 设置设置
android获得ImageView图片的等级问题 要实现的功能如下图,点击分享能显示选中与不选中状态,然后发送是根据状态来实现具体分享功能。...ImageView ss_indicator = (ImageView) view.findViewById(R.id.ss_indicator); // if (ss_indicator.isSelected
ImageView android:id="@+id/imageview_normal" android:layout_width="wrap_content" android:layout_height...:color/black" android:maxHeight="300dp" android:maxWidth="300dp" android:onClick="ivClicked"...ImageView的XML属性 android:src,设置ImageView要显示的图片; android:adjustViewBounds,是否保持宽高比,需要和maxWidth、maxHeight...一起使用,否则单独使用没有效果; android:maxWidth,设置View的最大宽度; android:maxHeight,设置View的最大高度; 如果想设置图片固定大小,又想保持图片宽高比,...需要这样设置: android:adjustViewBounds设置为true; android:maxWidth和android:maxHeight要设置; android:layout_width
* @attr ref android.R.styleable#ImageView_src * @attr ref android.R.styleable#ImageView_maxWidth...* @attr ref android.R.styleable#ImageView_maxHeight * @attr ref android.R.styleable#ImageView_tint...* @attr ref android.R.styleable#ImageView_scaleType * @attr ref android.R.styleable#ImageView_cropToPadding.../sp_16" ---- 三、adjustViewBounds 前提:1.保证layout_width、layout_height为wrap_content 2.设置了maxHeight、maxWidth...:maxHeight="50dp" android:maxWidth="50dp" android:adjustViewBounds="true" ---- 四、tint覆盖色:最好有透明度的颜色,不然图片就全盖住了
图片插入不难,主要是方式比较多,使用时具体参见第三张PPT
在 Android 应用开发中,我们通常使用 ImageView 来显示图片。 ImageView的主要属性 [1240] ImageView的使用 ImageView经常用来显示图片。...ImageView style="@style/IvDemo1" android:background="@drawable/pic_2_robots" /> ImageView...ImageView style="@style/IvDemo1" android:scaleType="fitXY" android:src="@drawable/pic_2_...ImageView style="@style/IvDemo1" android:layout_marginStart="20dp" android:scaleType="center...android:scaleType="fitCenter" android:src="@drawable/pic_2_robots" /> 例子: [1240] ImageView 视频教程参考
比如我的两张大小不同的图片,分别显示在96dp×96dp的ImageView上,会有不同的效果,代码如下: ImageView android:layout_width="96dp...ImageView android:layout_width="96dp" android:layout_height="128dp" android...android:scaleType="fitCenter" android:src="@drawable/big" /> ImageView android:...ImageView android:layout_width="48dp" android:layout_height="256dp" android:...ImageView android:layout_width="256dp" android:layout_height="48dp" android
,Fresco,Glide对比 前言 小伙伴们,在上文中我们介绍了Android视图控件Button控件,本文我们继续盘点,介绍一下Android视图控件中的第四个控件——ImageView。...一.ImageView基本介绍 在 Android 应用开发中,我们通常使用 ImageView 来显示图片。...二.ImageView常用主要属性介绍 android:src 设置图片资源 android:scaleType 设置图片缩放类型 android:alpha 设置图片透明度 src src 设置图片资源...:不改变原图大小,从imageview左上角开始绘制原图,原图超过imageview的部分作裁剪处理 alpha 设置透明度 ImageView android...="260dp" android:alpha="0.3" android:src="@mipmap/ic_launcher" /> 三.imageView
前言 今天有个以前学校的学弟使用ImageView加载图片时出现了布局空间多余的问题(想动态适配图片的大小),如下图所示。...一、先看下XML文件代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android...:layout_width="wrap_content" android:layout_height="wrap_content"> ImageView android...* * @see #getAdjustViewBounds() * * @attr ref android.R.styleable#ImageView_adjustViewBounds...ImageView android:layout_width="match_parent" android:layout_height="wrap_content"
ImageView ImageView是图片控件,就不在过多介绍了. ImageView提供了adjustViewBounds属性,用于设置缩放时是否保持原图长宽比。...单独设置不起作用,需要配合maxWidth和maxHeight属性一起使用。..." android:layout_height="match_parent"> ImageView android:id="@+id/header"...="true" android:maxHeight="80dp" android:maxWidth="80dp" android:padding="10dp...ImageView属性 Adapter基础讲解
UseCompoundDrawables 警告提示你可以使用 TextView 的 compound drawables 功能,而不是在布局中单独使用一个 ImageView 和 TextView。...使用这种方式比起分别放置 ImageView 和 TextView 更有效率,因为它减少了布局层次结构的复杂性,并且可以提升渲染性能。...end" android:lines="1" android:maxWidth="@dimen/dp_200" android:text="foo".../> ImageView android:id="@+id/gender" android:layout_width="@dimen/dp_17"...dimen/dp_4" android:ellipsize="end" android:lines="1" android:maxWidth="@dimen/dp_200"
我们都知道,在Android中如果想要显示一张图片,可以借助ImageView控件来完成,但是如果将一张GIF图片设置到ImageView里,它只会显示这张图片的第一帧,不会产生任何的动画效果。...ImageView无法播放GIF图片说明它的功能还不够强大,那么今天我们就来编写一个PowerImageView控件,让它既能支持ImageView控件原生的所有功能,同时还可以播放GIF图片。...可以看到,我们重写了ImageView中所有的构建函数,使得PowerImageView的用法可以和ImageView完全相同。在构造函数中,则是对所有必要的数据进行了初始化操作。...,PowerImageView的用法和ImageView几乎完全一样,使用android:src属性来指定一张图片即可,这里指定的anim就是一张GIF图片。...一张图片在布局正中央显示出来了,正是普通ImageView所具备的功能。你还可以在PowerImageView中指定android:scaleType等属性,用法和原生的ImageView完全一样。
none表示不设置间隔线。...android:paddingLeft="5dip" android:paddingTop="10dip" > ImageView...10dip" > ImageView android:layout_width="35dp" android:...10dip" > ImageView android:layout_width="35dp" android:...setMeasuredDimension方法对测量的值进行设置的,至于 maxWidth的值在源码的前面有相应的判断进行赋值,所以整个measure的方法基本围绕 maxWidth和mTotalLength
在我们平时的开发过程中,可以说图片展示是每个App必备的,所以我们会用到ImageView图片控件,对于每个Android开发者来说,这已经非常熟悉了,那有童鞋就会问了:这还有什么好讲的呢?...[scbxnhce9h.png] 3.android:scaleType=“center_crop” 以原图填满ImageView为目的 (1).当原图的size小于ImageView的size时...[grks4jaqil.png] 6.android:scaleType=“fit_start” 把原图按照比例放大缩小到ImageView的高度,显示在ImageView的start(前部/上部)...[iezpgioltv.png] 7.android:sacleType=“fit_center” 把原图按照比例放大缩小到ImageView的高度,显示在ImageView的center(中部/居中显示...[078l0ycz17.png] 8.android:scaleType=“fit_end” 把原图按照比例放大缩小到ImageView的高度,显示在ImageVIew的end(后部/尾部/底部)
自定义ImageView方法 写一个类让它继承ImageView,并增加一个setImageURL(path)方法 import android.content.Context; import android.graphics.Bitmap...; import android.graphics.BitmapFactory; import android.os.Handler; import android.os.Message; import...android.util.AttributeSet; import android.widget.ImageView; import android.widget.Toast; import java.io.IOException...:name="android.permission.INTERNET"/> 效果图 压缩 这是比较简单的从网络获取照片,直接在ImageView上显示,但是你有没有考虑过如果网络的图片很大,已经超出了手机屏幕的大小...; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.Toast; import
ml_maxWidth="200dp"> <TextView android:layout_width="match_parent" android:layout_height...="@android:color/holo_blue_light" app:ml_maxWidth="200dp" app:ml_maxheight="150dp"> <TextView..." app:ml_ratio="2.0" app:ml_ratio_standard="w_h"> ImageView android:layout_width...="0.8" app:ml_ratio_standard="h_w"> ImageView android:layout_width="match_parent"...:background="@android:color/holo_blue_light" app:ml_maxWidth="150dp"> ImageView android
android:scaleType=”centerCrop” 以填满整个ImageView为目的,将原图的中心对准ImageView的中心,等比例放大原图,直到填满ImageView为止(指的是ImageView...android:scaleType=”matrix” 不改变原图的大小,从ImageView的左上角开始绘制原图,原图超过ImageView的部分作裁剪处理。...android:scaleType=”fitCenter” 把原图按比例扩大或缩小到ImageView的ImageView的高度,居中显示 android:scaleType=”fitEnd” 把原图按比例扩大...(缩小)到ImageView的高度,显示在ImageView的下部分位置 android:scaleType=”fitStart” 把原图按比例扩大(缩小)到ImageView的高度,显示在ImageView...基本用不到的一个属性: ImageView的android:adjustViewBounds属性为是否保持原图的长宽比,单独设置不起作用,需要配合maxWidth或maxHeight一起使用。
领取专属 10元无门槛券
手把手带您无忧上云