美文网首页
android 按钮点击出现网络图片

android 按钮点击出现网络图片

作者: 池瑶瑶 | 来源:发表于2019-11-04 19:08 被阅读0次

    build.gradle

     implementation 'com.github.bumptech.glide:glide:4.9.0'
    

    AndroidManifest.xml

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

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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=".MainActivity"  android:orientation="vertical">
        <Button
            android:text="fitch"
            android:onClick="one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
       <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    </LinearLayout>
    

    MainActivity.java

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        }
        public void one(View view) {
            ImageView imageView =findViewById(R.id.image);
            String url="http://pic1.nipic.com/2009-02-18/200921821325953_2.jpg";
            Glide.with(this)
                    .load(url)
                    .circleCrop()
                    //边框为圆形
                    .into(imageView);
        }
    }
    

    相关文章

      网友评论

          本文标题:android 按钮点击出现网络图片

          本文链接:https://www.haomeiwen.com/subject/mvadbctx.html