zoukankan      html  css  js  c++  java
  • Android Studio [ImageView/使用第三方库加载图片]

    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"/>
  • 相关阅读:
    nyoj 游戏高手的烦恼 (二分图最小点覆盖)
    nyoj 三国志 (Dijkstra + 01背包)
    《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅱ
    《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅰ
    Java学习作业(14.4.21)
    2014上年度学习计划
    快速求幂(Quick Exponentiation)
    B. Inna and Nine
    B. Valera and Contest
    Problem 2128 最长子串
  • 原文地址:https://www.cnblogs.com/zlc364624/p/10705578.html
Copyright © 2011-2022 走看看