BadgedImageview
介绍:
一个为ImageView添加徽章,标记(badge)的库。从Nick Butcher(https://github.com/nickbutcher) 的Plaid app中提取出来的,做了一些修改。
运行效果:
使用说明:
-
设置 badge 颜色
-
设置 badge padding
-
设置 badge 文字
-
设置 badge gravity
-
设置 前景
-
代码中显示和隐藏badge。
Gradle 通过 jitpack
repositories {
// ...
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.yesidlazaro:BadgedImageview:1.0'
}
例子
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
BadgedFourThreeImageView badgedImageViewDog;
BadgedSquareImageView badgedImageViewPersonVideo;
BadgedSquareImageView badgedImageViewPersonGif;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
badgedImageViewDog = (BadgedFourThreeImageView) findViewById(R.id.badge_dog);
badgedImageViewPersonVideo = (BadgedSquareImageView) findViewById(R.id.badge_person_video);
badgedImageViewPersonGif = (BadgedSquareImageView) findViewById(R.id.badge_person_gif);
badgedImageViewDog.showBadge(true);
badgedImageViewPersonVideo.showBadge(true);
badgedImageViewPersonGif.showBadge(true);
badgedImageViewPersonGif.setBadgeText("JPG");
badgedImageViewPersonGif.setBadgeColor(getResources().getColor(R.color.gray_50));
badgedImageViewPersonGif.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (badgedImageViewPersonGif.isBadgeVisible()) {
badgedImageViewPersonGif.showBadge(false);
} else {
badgedImageViewPersonGif.showBadge(true);
}
}
}
<com.creativityapps.badgedimageviews.BadgedFourThreeImageView
android:id="@+id/badge_dog"
android:layout_width="300dp"
android:layout_height="200dp"
android:src="@drawable/dog"
app:badgeGravity="end|bottom"
app:badgePadding="@dimen/padding_normal"
app:badgeText="@string/lab_gif" />
<com.creativityapps.badgedimageviews.BadgedSquareImageView
android:id="@+id/badge_person_video"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="@dimen/padding_normal"
android:src="@drawable/me"
app:badgeColor="@color/colorAccent"
app:badgeGravity="top|right"
app:badgePadding="@dimen/padding_normal"
app:badgeText="@string/lab_video" />
<com.creativityapps.badgedimageviews.BadgedSquareImageView
android:id="@+id/badge_person_gif"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="@dimen/padding_normal"
android:src="@drawable/me"
android:foreground="?selectableItemBackground"
app:badgeGravity="top|left"
app:badgePadding="@dimen/padding_normal"
app:badgeText="@string/lab_gif" />
已下载
0