加依赖:
//圆形图片依赖:(一般和glide一起用): compile 'de.hdodenhof:circleimageview:2.2.0' //图片依赖比imagerloader更方便: compile 'com.github.bumptech.glide:glide:3.7.0'
加权限:
<uses-permission android:name="android.permission.INTERNET"/>
主方法:
public class MainActivity extends AppCompatActivity { private CircleImageView civ; String imgerUrl ="https://img-my.csdn.net/uploads/201407/26/1406383265_8550.jpg"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); civ = findViewById(R.id.civ); } public void click(View view) { Glide.with(this).load(imgerUrl).into(civ); } }
activity_main布局:
<?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="com.example.day_0524.MainActivity"> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="点我获得网络图片" android:onClick="click"/> <de.hdodenhof.circleimageview.CircleImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/civ"/> </RelativeLayout>