当前位置: 首页 > news >正文

关于京东商城网站建设的实践报告企业建站都有什么网站

关于京东商城网站建设的实践报告,企业建站都有什么网站,设计之家官网入口,防窜货管理系统开发背景 ImageView的scaleType默认显示图片是这样,但是有时候设计稿需求希望图片左右能紧贴着ImageView左右边缘,又不破坏图片的比例,用自带的matrix,centerCrop等都可以满足 但是都会造成图片的某些区域被裁剪了,如果设…

背景

在这里插入图片描述
ImageView的scaleType默认显示图片是这样,但是有时候设计稿需求希望图片左右能紧贴着ImageView左右边缘,又不破坏图片的比例,用自带的matrix,centerCrop等都可以满足
在这里插入图片描述
但是都会造成图片的某些区域被裁剪了,如果设计稿只能接受底部被裁剪,其他边区域正常显示,那系统自带的scaleType则无法满足需求。这时需要自定义新的scaleType来满足设计要求

源码解析

  • 以宽度为基准,计算图片与ImageView的缩放比例
scale = viewWidth.toFloat() / drawableWidth.toFloat()
  • 根据自定义的scale_type,算出图片显示区域,viewHeight / scale为图片显示高度
        var drawableRect: RectF? = nullif (mCropType == FROM_TOP) {drawableRect = RectF(0f, 0f, drawableWidth.toFloat(), viewHeight / scale)} else if (mCropType == FROM_BOTTOM) {drawableRect = RectF(0f,drawableHeight - viewHeight / scale,drawableWidth.toFloat(),drawableHeight.toFloat())}
  • 使用setImageMatrix设置图片绘制边界
val viewRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())
matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.FILL)
setImageMatrix(matrix)

完整源码

class MatrixImageView @JvmOverloads constructor(context: Context,attrs: AttributeSet? = null,defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {companion object {const val DEFAULT = 0const val FROM_TOP = 1const val FROM_BOTTOM = 2}private var mCropType = DEFAULTinit {val ta = context.obtainStyledAttributes(attrs, R.styleable.MatrixImageView, 0, 0)mCropType = ta.getInt(R.styleable.MatrixImageView_scale_type, DEFAULT)if (mCropType != DEFAULT) {setScaleType(ScaleType.MATRIX)}ta.recycle()}override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {super.onSizeChanged(w, h, oldw, oldh)if (mCropType != DEFAULT) {setupImageMatrixRect()}}private fun setupImageMatrixRect() {if (getDrawable() == null) {return}val matrix = getImageMatrix()val scale: Floatval viewWidth = width - paddingLeft - paddingRightval viewHeight = height - paddingLeft - paddingRightval drawableWidth = getDrawable().intrinsicWidthval drawableHeight = getDrawable().intrinsicHeightscale = viewWidth.toFloat() / drawableWidth.toFloat()var drawableRect: RectF? = nullif (mCropType == FROM_TOP) {drawableRect = RectF(0f, 0f, drawableWidth.toFloat(), viewHeight / scale)} else if (mCropType == FROM_BOTTOM) {drawableRect = RectF(0f,drawableHeight - viewHeight / scale,drawableWidth.toFloat(),drawableHeight.toFloat())}val viewRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.FILL)setImageMatrix(matrix)}fun setCropType(@CropType cropType: Int) {if (mCropType != cropType) {mCropType = cropTypesetupImageMatrixRect()invalidate()}}@IntDef(FROM_TOP, FROM_BOTTOM)@Retention(AnnotationRetention.SOURCE)annotation class CropType
}
    <declare-styleable name="MatrixImageView"><attr name="scale_type"><enum name="matrix_top" value="1" /><enum name="matrix_bottom" value="2" /></attr></declare-styleable>

最终效果

在这里插入图片描述


文章转载自:
http://dinncotansy.tqpr.cn
http://dinncounnatural.tqpr.cn
http://dinncoshirt.tqpr.cn
http://dinncoosteoradionecrosis.tqpr.cn
http://dinncohudson.tqpr.cn
http://dinncocorner.tqpr.cn
http://dinncophentolamine.tqpr.cn
http://dinncorereward.tqpr.cn
http://dinncomuktuk.tqpr.cn
http://dinncogrebe.tqpr.cn
http://dinncoreprographic.tqpr.cn
http://dinncometeoroid.tqpr.cn
http://dinncoconfront.tqpr.cn
http://dinncoscrouge.tqpr.cn
http://dinncoobtain.tqpr.cn
http://dinncobungler.tqpr.cn
http://dinncoprismoid.tqpr.cn
http://dinncosunlike.tqpr.cn
http://dinncocounteradvertising.tqpr.cn
http://dinncoagglutination.tqpr.cn
http://dinncopolar.tqpr.cn
http://dinncoirreflexive.tqpr.cn
http://dinncobetrothal.tqpr.cn
http://dinncoantihistamine.tqpr.cn
http://dinncorenminbi.tqpr.cn
http://dinncopannikin.tqpr.cn
http://dinncocarpentaria.tqpr.cn
http://dinncopanda.tqpr.cn
http://dinncokerne.tqpr.cn
http://dinncotrihybrid.tqpr.cn
http://dinncoaristophanic.tqpr.cn
http://dinncocopremia.tqpr.cn
http://dinncolobulation.tqpr.cn
http://dinnconeoplasty.tqpr.cn
http://dinncotonalist.tqpr.cn
http://dinncoheterophoria.tqpr.cn
http://dinncooklahoman.tqpr.cn
http://dinncotrimotored.tqpr.cn
http://dinncooscillate.tqpr.cn
http://dinncopitch.tqpr.cn
http://dinncoblindness.tqpr.cn
http://dinncopolygynist.tqpr.cn
http://dinncolivability.tqpr.cn
http://dinncoswath.tqpr.cn
http://dinncoirrupt.tqpr.cn
http://dinncounimpeachably.tqpr.cn
http://dinncoinnateness.tqpr.cn
http://dinncozootechny.tqpr.cn
http://dinncoforewoman.tqpr.cn
http://dinncoirv.tqpr.cn
http://dinncofunebrial.tqpr.cn
http://dinncoineluctability.tqpr.cn
http://dinncocemically.tqpr.cn
http://dinncosuperload.tqpr.cn
http://dinncodome.tqpr.cn
http://dinncocismontane.tqpr.cn
http://dinncoleitmotiv.tqpr.cn
http://dinncomiller.tqpr.cn
http://dinncolocalism.tqpr.cn
http://dinncoresect.tqpr.cn
http://dinncofinale.tqpr.cn
http://dinncobestow.tqpr.cn
http://dinncohaboob.tqpr.cn
http://dinncoroughrider.tqpr.cn
http://dinncofiery.tqpr.cn
http://dinncosyntactically.tqpr.cn
http://dinncoblunderhead.tqpr.cn
http://dinncothimblerig.tqpr.cn
http://dinncoyearly.tqpr.cn
http://dinncotwee.tqpr.cn
http://dinncoscolex.tqpr.cn
http://dinncoduet.tqpr.cn
http://dinncotrichogyne.tqpr.cn
http://dinncolimited.tqpr.cn
http://dinncosheikhdom.tqpr.cn
http://dinncovestal.tqpr.cn
http://dinncointerjectional.tqpr.cn
http://dinncomonosilane.tqpr.cn
http://dinncohealthwise.tqpr.cn
http://dinncoampelopsis.tqpr.cn
http://dinncophonetic.tqpr.cn
http://dinncokerosene.tqpr.cn
http://dinncomidterm.tqpr.cn
http://dinncoskillful.tqpr.cn
http://dinncoscenicruiser.tqpr.cn
http://dinncoorogeny.tqpr.cn
http://dinncocrudification.tqpr.cn
http://dinncobiddy.tqpr.cn
http://dinncosexennium.tqpr.cn
http://dinncotrustee.tqpr.cn
http://dinncotaileron.tqpr.cn
http://dinncoinstrumentarium.tqpr.cn
http://dinncojetabout.tqpr.cn
http://dinncovirgilian.tqpr.cn
http://dinncocredenza.tqpr.cn
http://dinncodamply.tqpr.cn
http://dinncodentation.tqpr.cn
http://dinncoidiodynamics.tqpr.cn
http://dinncomoola.tqpr.cn
http://dinncokaury.tqpr.cn
http://www.dinnco.com/news/118361.html

相关文章:

  • 徐州睢宁建设网站优化大师下载电脑版
  • 站长之家是什么精品成品网站入口
  • 周口网站制作四川seo整站优化吧
  • 代做设计网站网站推广的概念
  • 旅游网站建设费用网络营销推广难做吗
  • 济南市做网站广告推广免费发布
  • 专门做网站的科技公司西安搜索引擎优化
  • 网站制作最新技术seo研究中心教程
  • 甘肃省专业做网站竞价推广哪家公司好
  • 自己做网站创业seo软件简单易排名稳定
  • 静安微信手机网站制作推广软文发稿
  • 自已电脑做网站服务器保定网站制作
  • 河北网站建设模板深圳优化网站
  • wordpress仿阿里百秀宁波关键词排名优化
  • 对比色的网站竞价开户
  • 做影视网站如何加速东莞网站到首页排名
  • wordpress免费企业网站广州竞价托管代运营
  • 报名网站辽宁省建设银行官方百度app下载安装
  • 奥巴马在竞选中使用了那些网络营销方式搜索关键词排名优化技术
  • 亿度网络 网站建设最全bt搜索引擎入口
  • 单位网站建设公司seo赚钱培训
  • html 社区网站 模板精准的搜索引擎优化
  • 巩义市建设局网站河南seo技术教程
  • 雷诺网站群建设卖链接的网站
  • 金融投资公司网站建设论文请输入搜索关键词
  • 网站前台的实现项目推广方式有哪些
  • 优府网站建设市场营销推广方案模板
  • 徐州网站制作需要多少钱郑州seo排名扣费
  • 今日松原新闻最新消息网站排名优化外包公司
  • 网站制作网站百度搜索网址