zoukankan      html  css  js  c++  java
  • 实现ImageView宽度填满屏幕

    1.重写View的onMeasure方法(参考博客:http://www.jianshu.com/p/c9424615e99d)

    核心代码

    protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){

    Drawable d = getDrawable();if(d!=null){// ceil not round - avoid thin vertical gaps along the left/right edgesintwidth = MeasureSpec.getSize(widthMeasureSpec);//高度根据使得图片的宽度充满屏幕计算而得intheight = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth());

    setMeasuredDimension(width, height);

    }else{super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }

    2.设置ImageView的属性:

    //宽度填满屏幕

    android:layout_width=”match_parent”

    android:scaleType=”fitXY”

    android:layout_height=”wrap_content”

    //保持比例,一定要设置

    android:adjustViewBounds=”true”

    android:src = "@drawable/icon1"

    3.将ImageVIew的属性src改成background

  • 相关阅读:
    toj 2819 Travel
    toj 2807 Number Sort
    zoj 2818 Prairie dogs IV
    zoj 1276 Optimal Array Multiplication Sequence
    toj 2802 Tom's Game
    toj 2798 Farey Sequence
    toj 2815 Searching Problem
    toj 2806 Replace Words
    toj 2794 Bus
    css截取字符
  • 原文地址:https://www.cnblogs.com/new-comer/p/5306800.html
Copyright © 2011-2022 走看看