星空网 > 软件开发 > ASP.net

谷歌电子市场4

谷歌电子市场4

1.json

谷歌电子市场4

谷歌电子市场4

2.按照指定比例展示宽高的自定义控件实现

为了让图片按照完美比例进行展现, 不被压缩, 需要自定义控件,该控件可以根据预设的比例来确定宽高

 * 按照比例展示宽高的自定义控件 * * @author Kevin * */public class RatioLayout extends FrameLayout {  private float ratio;  public RatioLayout(Context context, AttributeSet attrs, int defStyle) {    super(context, attrs, defStyle);  }  public RatioLayout(Context context, AttributeSet attrs) {    super(context, attrs);    // 加载自定义属性的值    TypedArray typedArray = context.obtainStyledAttributes(attrs,        R.styleable.RatioLayout);    // 根据属性id获取属性值, 方式: R.styleable.名称_属性    ratio = typedArray.getFloat(R.styleable.RatioLayout_ratio, 0);    // 回收TypedArray, 释放内存    typedArray.recycle();  }  public RatioLayout(Context context) {    super(context);  }  @Override  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {    int widthMode = MeasureSpec.getMode(widthMeasureSpec);    int heightMode = MeasureSpec.getMode(heightMeasureSpec);    int widthSize = MeasureSpec.getSize(widthMeasureSpec);    int heightSize = MeasureSpec.getSize(heightMeasureSpec);    // MeasureSpec.EXACTLY 确定值, 比如把宽高值写死,或者match_parent    // MeasureSpec.AT_MOST 至多, 能撑多大就多大, 类似wrap_content    // MeasureSpec.UNSPECIFIED 未指定大小    if (widthMode == MeasureSpec.EXACTLY        && heightMode != MeasureSpec.EXACTLY && ratio != 0) {      // 1. 根据布局宽度推算图片宽度      int imageWidth = widthSize - getPaddingLeft() - getPaddingRight();      // 2. 根据图片宽度和宽高比,推算图片高度      int imageHeight = (int) (imageWidth / ratio);      // 3. 根据图片高度, 推算布局高度      heightSize = imageHeight + getPaddingTop() + getPaddingBottom();      // 4. 根据布局高度, 推算heightMeasureSpec      heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize,          MeasureSpec.EXACTLY);    }    super.onMeasure(widthMeasureSpec, heightMeasureSpec);  }}

自定义属性

values/attrs.

  

  

 




原标题:谷歌电子市场4

关键词:谷歌

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

赢麻了!卖家单量暴涨20倍,又一个“淘金地”被发现:https://www.ikjzd.com/articles/1573493064451481602
我在TikTok卖漱口水,卖到印尼第一:https://www.ikjzd.com/articles/1573493717773049858
Shopee东南亚全面进入精品时代!:https://www.ikjzd.com/articles/1573495917903601665
涉及大批卖家,这些爆品禁入美国!337调查你中招了吗?:https://www.ikjzd.com/articles/1573500215261306882
90后在非洲卖家电:从创维辞职,我决定创建自己的品牌:https://www.ikjzd.com/articles/1573500408656470017
突发!亚马逊下架3万个产品,旺季小心这些侵权雷区-跨标云:https://www.ikjzd.com/articles/1573503959545847809
桂林酒店销售多少钱 桂林旅游宾馆价格:https://www.vstour.cn/a/410227.html
十里银滩旅游攻略玩什么住哪里怎么去?:https://www.vstour.cn/a/410228.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流