前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android 中的那些圆角

Android 中的那些圆角

作者头像
码客说
发布2019-10-22 16:57:45
1.1K0
发布2019-10-22 16:57:45
举报
文章被收录于专栏:码客码客码客

引用关键字

implement、api和compile区别

图片圆角

加载处理原图圆角

Glide和Picasso

Glide

使用扩展Glide Transformations

repositories {
    jcenter()
}

dependencies {
    implementation 'jp.wasabeef:glide-transformations:3.1.1'
    // If you want to use the GPU Filters
    implementation 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}

设置代码

Glide.with(this).load(url)
        .apply(bitmapTransform(new BlurTransformation(25)))
        .into((ImageView) findViewById(R.id.image));
Picasso

使用扩展picasso-transformations

引用

repositories {
    jcenter()
}

dependencies {
    compile 'jp.wasabeef:picasso-transformations:2.2.1'
    // If you want to use the GPU Filters
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}

使用

Picasso.with(mContext).load(R.drawable.demo)
    .transform(transformation)
    .transform(new CropCircleTransformation())
    .into(holder.image);

Fresco

第一步:引入支持

dependencies {
  implementation 'com.facebook.fresco:fresco:1.8.1'
}

第二步:使用SimpleDraweeView代替ImageView

<?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"
                android:layout_width="wrap_content"
                android:layout_height="match_parent">>

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/iamgeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:roundedCornerRadius="2dp"/>

</RelativeLayout>

注意其中的:

app:roundedCornerRadius=”2dp”

这样你就得到了一个2dp圆角的ImageView。

初始化

public class MyApplication extends Application {
	@Override
	public void onCreate() {
		super.onCreate();
		Fresco.initialize(this);
	}
}

加载图片

Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);

圆角图片组件

RoundedImageView

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.makeramen:roundedimageview:2.3.0'
}

XML中应用

<com.makeramen.roundedimageview.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="fitCenter"
        app:riv_corner_radius="30dip"
        app:riv_border_width="2dip"
        app:riv_border_color="#333333"
        app:riv_mutate_background="true"
        app:riv_tile_mode="repeat"
        app:riv_oval="true" />

代码中应用

RoundedImageView riv = new RoundedImageView(context);
riv.setScaleType(ScaleType.CENTER_CROP);
riv.setCornerRadius((float) 10);
riv.setBorderWidth((float) 2);
riv.setBorderColor(Color.DKGRAY);
riv.mutateBackground(true);
riv.setImageDrawable(drawable);
riv.setBackground(backgroundDrawable);
riv.setOval(true);
riv.setTileModeX(Shader.TileMode.REPEAT);
riv.setTileModeY(Shader.TileMode.REPEAT);

背景圆角

<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android">  
	<solid android:color="#60000000"/>  
	<stroke android:width="3dp" color="#ff000000"/>  
	<corners android:radius="10dp" />  
</shape>

容器圆角(CardView)

引用

dependencies {  
    implementation 'com.android.support:cardview-v7:27.0.2'
}

设置

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    android:id="@+id/cardview"  
    app:cardCornerRadius="8dp"  
    app:cardBackgroundColor="@color/black"  
    android:layout_margin="8dp"  
    android:layout_height="80dp"  
    android:layout_width="match_parent">  
    
</android.support.v7.widget.CardView>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-03-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 引用关键字
  • 图片圆角
    • 加载处理原图圆角
      • Glide
      • Picasso
    • Fresco
      • 圆角图片组件
      • 背景圆角
      • 容器圆角(CardView)
      相关产品与服务
      容器服务
      腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档