Android Studio [ImageView/使用第三方库加载图片]

摘要:
xmlversion=“1.0”encoding=“utf-8”?

ImageViewActivity.class

package com.xdw.a122;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;


public class ImageViewActivity extends AppCompatActivity {
    private ImageView mIv4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imageview);
        mIv4=findViewById(R.id.iv_2);
        Glide.with(this).load("https://www.baidu.com/img/bd_logo1.png?where=super").into(mIv4);

    }
}

activity_imageview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ImageViewActivity"
    android:padding="15dp">

    <ImageView
        android:id="@+id/iv_1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:src="@drawable/back_1"
        android:scaleType="fitCenter"/>
    <ImageView
        android:id="@+id/iv_2"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:scaleType="fitCenter"
        android:background="#000000"
        android:layout_below="@id/iv_1"
        android:layout_marginTop="20dp"/>
</RelativeLayout>

并在build.gradle中添加

repositories {
mavenCentral()
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

在AndroidManifest.xml中的<application/>中添加网络权限

<uses-permission android:name="android.permission.INTERNET"/>

我学习的:

//导入网络图片
mIv4=findViewById(R.id.iv_2);
Glide.with(this).load("https://www.baidu.com/img/bd_logo1.png?where=super").into(mIv4);
//ImageView块
scaleType= 填充方式
fitCenter 按比例填充直到填满
fitXY 直接填充可能拉伸图片
center crop 按比例填充满,多余切割不显示
<ImageView
  android:id="@+id/iv_2"
  android:layout_width="match_parent"
  android:layout_height="200dp"
  android:scaleType="fitCenter"
  android:background="#000000"
  android:layout_below="@id/iv_1"
  android:layout_marginTop="20dp"/>

免责声明:文章转载自《Android Studio [ImageView/使用第三方库加载图片]》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Python有返回值的函数_布尔函数React事件机制下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

android layout 按比例布局

为了创建比例大小的子View,可以将LinearLayout的宽度和高度设为fill_parent, 而将子View的宽度或是高度设为0,然后为子View设置不同权重(weight) ,这样子View的大小就会权值成比例。 本例使用横向LinearLayout,LinearLayout的android:layout_width=”match_paren...

android中LitePal的使用

网上有一篇文章写的挺好的,推荐给大家:安卓项目实战之:数据库框架 LitePal 3.0 的使用详解 LitePal是对SQLite数据库操作进行了封装,采用对象映射的方式操作SQLite数据库,简化了对SQLiter的操作 我也是使用的是最新的LitePal3.0 1、首先添加依赖,引入LitePal3.0,在build.gradle中添加如下内容: i...

[置顶] xamarin android使用gps定位获取经纬度

看了文章你会得出以下几个结论 1.android定位主要有四种方式GPS,Network(wifi定位、基站定位),AGPS定位 2.绝大部分android国产手机使用network进行定位是没有作用的,肯定是无法获取获取位置信息(当然也肯定是有办法解决这种问题的) 3.android 的GPS定位需要一定时间的,大概一分钟左右。 4.andro...

pixel和nexus设备安卓9.0/8.1/7.1.x/6.x WiFi和信号图标出现叉x号或者感叹号的消除办 法

在安卓9.0/8.1/8.0/7.1.2里如何消除x号(在老一点点版本是感叹号)呢? 1.首先开启usb调试,然后用数据线连接电脑和手机。 2.然后解决好您的adb驱动问题,具体教程见:http://www.pixcn.cn/thread-1084-1-1.html 3.在电脑开始菜单-运行 输入cmd,打开命令提示符 依次输入下面语句 (以下办法支持安卓...

android:duplicateParentState属性

xml文件 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:la...

app常见性能测试点

转载链接:https://blog.csdn.net/xiaomaoxiao336368/article/details/83547318普遍的apk性能测试,主要是以下七类1、响应2、内存3、cpu4、FPS (app使用的流畅度)5、GPU过度渲染6、耗电7、耗流(app除了这些性能测试,还有:手机版本号兼容性,屏幕分辨率兼容性,稳定性测试,安全测试等...