zoukankan      html  css  js  c++  java
  • 一手遮天 Android

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

    一手遮天 Android - view(媒体类): ImageView 基础

    示例如下:

    /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

  • 相关阅读:
    Lua的各种资源2
    Lua的各种资源1
    游戏AI:行为树
    关于资源包存储资源路径名的方案
    scrapy爬虫笔记(创建一个新的项目并运行)
    scrapy爬虫笔记(安装)
    运行scrapy报错:You do not have a working installation of the service_identity module
    运行scrapy demo时报错:[twisted] CRITICAL: Unhandled error in Deferred
    python3下使用有道翻译网页版实现翻译功能~~~附源码
    python3+openCV实现图片的人脸人眼检测,原理+参数+源代码
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_media_ImageViewDemo1.html
Copyright © 2011-2022 走看看