一手遮天 AndroID - vIEw(媒体类): ImageVIEw 基础示例如下:项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd
/vIEw/media/ImageVIEwDemo1.java
/** * ImageVIEw - 图片控件 * * 本例用于演示 ImageVIEw 基础 * * 注:关于网络图片的显示和缓存,以及图片的处理之类的建议使用 Picasso 框架 */package com.webabcd.androIDdemo.vIEw.media;import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.Widget.ImageVIEw;import com.webabcd.androIDdemo.R;import com.webabcd.androIDdemo.utils.Helper;public class ImageVIEwDemo1 extends AppCompatActivity { private ImageVIEw _imageVIEw4; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_vIEw_media_imagevIEwdemo1); _imageVIEw4 = (ImageVIEw)findVIEwByID(R.ID.imageVIEw4); sample(); } private voID sample() { // 设置 src _imageVIEw4.setimageDrawable(Helper.ID2drawable(this, R.drawable.img_sample_son)); // 设置 background // _imageVIEw4.setBackground(Helper.ID2drawable(this, R.drawable.img_sample_son)); }}
/layout/activity_vIEw_media_imagevIEwdemo1.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"> <!-- ImageVIEw - 图片控件 --> <!-- 用 background 显示图片,图片会自动拉伸并填充满整个控件 --> <ImageVIEw androID:ID="@+ID/imageVIEw1" androID:layout_wIDth="300dp" androID:layout_height="150dp" androID:background="@drawable/img_sample_son"/> <!-- 用 src 显示图片,默认情况下图片会等比缩放,其他更多的缩放方式的相关介绍请参见 vIEw/media/ImageVIEwDemo2 用 src 显示图片,图片支持通过 Alpha 来指定不透明度 --> <ImageVIEw androID:ID="@+ID/imageVIEw2" androID:layout_wIDth="300dp" androID:layout_height="150dp" androID:src="@drawable/img_sample_son" androID:Alpha="0.3"/> <!-- 为了让 ImageVIEw 支持 maxWIDth 和 maxHeight 需要将 adjustVIEwBounds 设置为 true --> <ImageVIEw androID:ID="@+ID/imageVIEw3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:src="@drawable/img_sample_son" androID:adjustVIEwBounds="true" androID:maxHeight="100px" androID:maxWIDth="200px" /> <!-- 在 java 中设置 ImageVIEw 的 src 或 background --> <ImageVIEw androID:ID="@+ID/imageVIEw4" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" /></linearLayout>
总结项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd
以上是内存溢出为你收集整理的一手遮天 Android - view(媒体类): ImageView 基础全部内容,希望文章能够帮你解决一手遮天 Android - view(媒体类): ImageView 基础所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)