[英]Android - How to create a view like this using recycler view?
Can anyone help me with this custom layout inside a card view? 有人可以在名片视图中使用此自定义布局来帮助我吗? I am showing a list of items and need to show an item like this.
我正在显示项目列表,需要显示一个这样的项目。 But cant understand how to implement this.
但是无法理解如何实现这一点。
Basically, There is a recycler view Inside it, there are cards. 基本上,这里有一个回收站视图,里面有卡片。 The card has a blurry background image.
卡的背景图像模糊。 On the top of it, there is a view that is similat to this.
在它的顶部,有一个与此相似的视图。 Below, there are textviews, which i have implemented.
下面是我已实现的textview。
But this thing is a real confusion. 但是,这是一个真正的混乱。 Cant understand how to make this happen.
不能理解如何做到这一点。
Try something like this. 尝试这样的事情。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="70dp"
android:layout_height="22.27dp"
android:background="@drawable/img_online_scoreboard_text_background" >
<TextView
android:id="@+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/playerImageView"
android:ellipsize="end"
android:gravity="bottom|left"
android:lines="1"
android:scrollHorizontally="true"
android:textColor="#FFFFFF"
android:textSize="5dp" />
<ImageView
android:id="@+id/playerImageView"
android:layout_width="22.27dp"
android:layout_height="22.27dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="0.5dp" />
</RelativeLayout>
img_online_scoreboard_text_background.xml img_online_scoreboard_text_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#A5FFFFFF" />
<stroke
android:width="0dp"
android:color="#00FFFFFF" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
Set round image programmatically 以编程方式设置圆形图像
public static Bitmap getCircularBitmap(Bitmap bm) {
if(bm == null) {
return bm;
}
int sice = Math.min((bm.getWidth()), (bm.getHeight()));
Bitmap bitmap = ThumbnailUtils.extractThumbnail(bm, sice, sice);
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xffff0000;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setFilterBitmap(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawOval(rectF, paint);
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth((float) 4);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
Use it like: 像这样使用它:
imageView.setImageBitmap(getCircularBitmap(bitmap));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.