对于图像的显示处理,之前关注过一篇文章:ImageView.ScaleType设置图解
http://blog.csdn.net/larryl2003/article/details/6919513,主要是通过android:scaleType来定义,
1. SetScaleType(ImageView.ScaleType.CENTER);按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示
2. SetScaleType(ImageView.ScaleType.CENTER_CROP);按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)
3. setScaleType(ImageView.ScaleType.CENTER_INSIDE);将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽
4. setScaleType(ImageView.ScaleType.FIT_CENTER);把图片按比例扩大/缩小到View的宽度,居中显示
5. FIT_XY;不按比例缩放图片,目标是把图片塞满整个View。

但是,如果要让图片宽度填满屏幕宽度,而图片又不拉升变形,也就是让其适应屏幕宽度,而图片高度则相应的缩放。

 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.about_us);        int bwidth = bitmap.getWidth();        int bHeight = bitmap.getHeight();        DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();        int width = displayMetrics.widthPixels;        int height = width * bHeight / bwidth;        ViewGroup.LayoutParams para = about_us.getLayoutParams();//        final float scale = getResources().getDisplayMetrics().density;        para.height = height;        about_us.setLayoutParams(para);

而对应的布局

<?xml version="1.0" encoding="utf-8"?><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="vertical">    <android.support.v7.widget.Toolbar  android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" /><!--如果图片高度太高,超过屏幕高度的话建议使用scrollView-->    <ScrollView  android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content">        <ImageView  android:id="@+id/about_us" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/about_us" />    </ScrollView></LinearLayout>

更多相关文章

  1. Android系列教程之六:TextView小组件的使用--附带超链接和跑马灯
  2. android程序在Layout中设置控件水平或垂直居中
  3. Android(安卓)Activity之间传递图片(Bitmap)的方法
  4. Android中WebView获取网页中标题 ,内容, 图片的方法
  5. Android的onCreateOptionsMenu()创建菜单Menu详解
  6. android异步更新UI
  7. android计数器――基础编
  8. android应用程序跳转到系统的各个设置页面
  9. android 下改变默认的checkbox的 选中 和被选中 图片

随机推荐

  1. [置顶] Android(安卓)轻松实现仿QQ消息下
  2. Android以最简单的方式接入支付
  3. android核心基础(1)_什么是3G
  4. Android有效获取状态栏(StatusBar)高度的
  5. Android 崩溃分析 方法论
  6. android之多线程
  7. Android安全模型之Android安全机制(进程沙
  8. 学习 Android 平台 OpenGL ES API,了解 Op
  9. Google手机OS大战:Android挟免费开源优势
  10. Android Market v3.3.11 APK 正式释出,增