Skip to content

Commit

Permalink
修改卡片的圆角图片
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqirong committed Mar 3, 2017
1 parent 0de6b01 commit 034192e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
61 changes: 61 additions & 0 deletions app/src/main/java/com/yuqirong/cardswipeview/RoundImageView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.yuqirong.cardswipeview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
* @author maomao
* @email qirong.yu@jubaobar.com
* @date 2017-3-3
*/

public class RoundImageView extends ImageView {

private Path mPath;
private RectF mRectF;
private float[] rids = new float[8];

public RoundImageView(Context context) {
this(context, null);
}

public RoundImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RoundImageView);
float mRadius = array.getDimension(R.styleable.RoundImageView_radius, 10);
rids[0] = mRadius;
rids[1] = mRadius;
rids[2] = mRadius;
rids[3] = mRadius;
rids[4] = 0f;
rids[5] = 0f;
rids[6] = 0f;
rids[7] = 0f;
array.recycle();
mPath = new Path();
}

@Override
protected void onDraw(Canvas canvas) {
mPath.reset();
mPath.addRoundRect(mRectF, rids, Path.Direction.CW);
canvas.clipPath(mPath);
super.onDraw(canvas);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mRectF = new RectF(0, 0, w, h);
}

}
4 changes: 3 additions & 1 deletion app/src/main/res/layout/item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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"
android:layout_width="336dp"
android:layout_height="426dp"
android:background="@drawable/shape_background"
Expand All @@ -12,11 +13,12 @@
android:layout_height="0dp"
android:layout_weight="1">

<ImageView
<com.yuqirong.cardswipeview.RoundImageView
android:id="@+id/iv_avatar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:radius="5dp"
android:src="@drawable/img_avatar" />

<ImageView
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="RoundImageView">
<attr name="radius" format="reference|dimension" />
</declare-styleable>
</resources>
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'

classpath 'com.novoda:bintray-release:0.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -16,6 +16,11 @@ allprojects {
repositories {
jcenter()
}
tasks.withType(Javadoc) {
options {
encoding "UTF-8" charSet 'UTF-8' links "http://docs.oracle.com/javase/7/docs/api"
}
}
}

task clean(type: Delete) {
Expand Down
10 changes: 10 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 25
Expand Down Expand Up @@ -29,3 +30,12 @@ dependencies {
compile 'com.android.support:recyclerview-v7:25.1.1'
testCompile 'junit:junit:4.12'
}

publish {
userOrg = 'yyyuqirong'
groupId = 'me.yuqirong'
artifactId = 'cardswipeview'
publishVersion = '1.0.0'
desc = 'the item of recyclerview can swipe'
website = 'https://github.com/yuqirong/CardSwipeView'
}

0 comments on commit 034192e

Please sign in to comment.