zoukankan      html  css  js  c++  java
  • android ImageView 宽度设定,高度自适应

    最近碰到一个需求,要求是在不知道图片宽度和高度的情况下,让图片在指定宽度内充满,同时高度自适应,在网络上查找了一下,也有很多解决方法,后来针对自己的应用,选择了一个修改较小的方案,最后证明效果还是蛮不错的,记录在这里,希望能帮助到有同样需求的人。

    首先,需要给你的ImageView布局加上android:adjustViewBounds="true"

     <ImageView
                android:id="@+id/iv_custom_showdress_item_dress"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"/>

    然后,在代码里设置ImageView.最大宽度和最大高度,因为adjustViewBounds属性只有在设置了最大高度和最大宽度后才会起作用

    WindowManager wm = (WindowManager) _context.getSystemService(Context.WINDOW_SERVICE);
                int screenWidth = wm.getDefaultDisplay().getWidth();
                ViewGroup.LayoutParams lp = viewHolder.showDress.getLayoutParams();
                lp.width = screenWidth;
                lp.height = LayoutParams.WRAP_CONTENT;
                viewHolder.showDress.setLayoutParams(lp);
  • 相关阅读:
    FileWatcher
    virtual table(有180个评论)
    this 指针
    docker -ce(社区免费版)
    vue-cli
    CAP理论、BASE理论
    B+树和LSM存储引擎代表树和B-树
    CPU高速缓存
    Python&基础环境搭建
    二叉树
  • 原文地址:https://www.cnblogs.com/jxyZ/p/4403424.html
Copyright © 2011-2022 走看看