使用
FloatingActionButton
而不是
浮动操作按钮
ImageView
与第三方库类似
Picasso
或
Glide
加载和转换
Image
资源您也可以使用
CircleImageView
解决方案1:
使用
具有
Picasso
格拉德尔:
dependencies {
.........
compile 'com.squareup.picasso:picasso:2.5.2'
}
用法:
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">
<ImageView
android:id="@+id/image_header"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/dummy_background"/>
<ImageView
android:id="@+id/image_profile_pic"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="125dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
ImageView imageProfilePic = (ImageView) findViewById(R.id.image_profile_pic);
Picasso.with(this)
.load(R.drawable.dummy_profile_pic)
.resize(150, 150)
.centerCrop()
.transform(new CircleTransform())
.into(imageProfilePic);
解决方案2:
图片框
具有
Glide
.
格拉德尔:
dependencies {
.........
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
}
XML
<?xml版本=“1.0”编码=“utf-8”&燃气轮机;
<RelativeLayout xmlns:android=”http:
xmlns:app=”http:
android:layout\u width=“匹配父对象”
android:layout\u height=“match\u parent”>
android:id=“@+id/image\u头”
android:layout_height=“200dp”
android:background=“@drawable/dummy\u background”/>
android:id=“@+id/image\u profile\u pic”
android:layout_height=“150dp”
android:layout\u marginTop=“125dp”
JAVA
ImageView imageProfilePic = (ImageView) findViewById(R.id.image_profile_pic);
Glide.with(this)
.load(R.drawable.dummy_profile_pic)
.apply(RequestOptions.circleCropTransform())
.into(imageProfilePic);
解决方案3:
CircleImageView
图书馆
格拉德尔:
dependencies {
.........
compile 'de.hdodenhof:circleimageview:2.1.0'
}
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">
<ImageView
android:id="@+id/image_header"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/dummy_background"/>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_profile_pic"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="125dp"
android:layout_centerHorizontal="true"
app:civ_border_width="2dp"
app:civ_border_color="#FFFFFF"/>
</RelativeLayout>
CircleImageView imageProfilePic = (CircleImageView) findViewById(R.id.image_profile_pic);
Picasso.with(this)
.load(R.drawable.dummy_profile_pic)
.into(imageProfilePic);
希望这会有所帮助~