zoukankan      html  css  js  c++  java
  • roid中的图片怎么能自适应呢??适应各种的大小的屏幕??

    layout中设置图片自适应大小,并且设置最大宽高,当图片的宽高大于设置的最大值时,宽高值为设置的最大值。

    view plaincopy to clipboardprint?
    <ImageView Android:id="@+id/image_view"    
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:adjustViewBounds="true" 
          android:maxWidth="42dp" 
          android:maxHeight="42dp" 
          android:scaleType="fitCenter" 
          android:layout_marginLeft="3dp" 
          android:src="@drawable/icon" 
          /> 
      <ImageView android:id="@+id/image_view" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxWidth="42dp"
            android:maxHeight="42dp"
            android:scaleType="fitCenter"
            android:layout_marginLeft="3dp"
            android:src="@drawable/icon"
            />

    关键代码:

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxWidth="42dp"
            android:maxHeight="42dp"

    代码

    ImageView iv = new ImageView(...);
    iv.setImageResource(...);
    iv.setScaleType(ImageView.ScaleType.FIT_XY);
    iv.setAdjustViewBounds(true);
    iv.setMaxHeight(130);//高度
    iv.setMaxWidth(130);//宽度			
    return iv;
  • 相关阅读:
    DynamoDB-条件表达式ConditionExpression
    更新表达式updateExpression
    AWS AppSync 的基本语句
    post和get的区别
    图片缩小右移旋转
    加入购物车飞入特效
    c# out参数直接写法
    unity vs 重复打开
    canvas与sprite射线检测
    MySQL语法大全
  • 原文地址:https://www.cnblogs.com/soonfly/p/2254662.html
Copyright © 2011-2022 走看看