最近在图片上犯了迷糊,在礼拜天抽出时间把属性一个一个

试了一遍,在这里和大家分享一下

ImageView的属性:

android:src 用于显示图片

android:maxWidth="" 最大宽度
android:minHeight="" 最小高度
android:maxHeight="" 最大高度
android:minHeight="" 最小高度

上面四个属性需要设置android:adjustViewBounds 属性设置为true 否则不起作用

为了验证看下面的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >   <ImageView       android:id="@+id/iamgeView1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"            android:src="@drawable/a" />    </LinearLayout>


设置一下代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >   <ImageView       android:id="@+id/iamgeView1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"               android:maxHeight="100dp"       android:maxWidth="100dp"       android:src="@drawable/a" />    </LinearLayout>

效果没有改变,那添加上android:adjustViewBounds="true"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal" >   <ImageView       android:id="@+id/iamgeView1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:adjustViewBounds="true"       android:maxHeight="100dp"       android:maxWidth="100dp"       android:src="@drawable/a" />    </LinearLayout>
在看效果图


提醒 这个最大和最小是相对的,当你直接设置

android:layout_width=""
android:layout_height=""

之后图片的最大和和最小就失去作用了,而是直接取决于图片本身。



android:adjustViewBounds :是否调整图片的边界来保持显示的长宽比

这个属性也是常用的,比如有的时候我们喜欢个图片的宽和高设置为具体的数字

其实可以这样设置的,有时候你可能感觉设置了不起作用那是因为最大或最小的

数值你没有设置的原因,其实这句话就是自己写这边博客的原因,



   <ImageView       android:id="@+id/iamgeView1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:adjustViewBounds="true"       android:maxHeight="300dp"       android:maxWidth="100dp"       android:src="@drawable/a" />

把宽和高自适应设置最大和最小,也能达到想要的效果, 有时候图片可能太大不能显示,自己看代码很久也找不到原因

不放设置下

android:adjustViewBounds="true"看看是不是图片太大的原因
  

android:scaleType="":是控制图片如何resized/moved来匹对ImageViewsize

属性有:

center 按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示

centerCrop 按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)

centerInside 将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽

fitCenter 把图片按比例扩大/缩小到View的宽度,居中显示

fitEnd 把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置

fitStart 把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置

fitXY 把图片不按比例扩大/缩小到View的大小显示






更多相关文章

  1. Android窗口机制(五)最终章:WindowManager.LayoutParams和Token以及
  2. android 常用 属性
  3. Android(安卓)Switch属性全记录
  4. 浅谈android的selector,背景选择器
  5. ANDROID 输入法出现挤压屏幕、ANDROID输入键盘覆盖了屏幕控件的
  6. Android(安卓)模拟器横屏竖屏切换设置
  7. Android的ps命令介绍和技巧
  8. android环境变量的设置及注意问题
  9. 图片自适应imageView属性

随机推荐

  1. Android_day04
  2. Android(安卓)layout属性大全
  3. qt for android
  4. Android(安卓)Studio 官方示例源码地址
  5. android广播动态注册与发送流程分析
  6. android横屏竖屏
  7. RelativeLayout常用属性介绍-----开发日
  8. Android(安卓)布局属性大全
  9. android布局属性
  10. Android