简体   繁体   English

Android-如何使用回收站视图创建类似的视图?

[英]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.

相关问题 如何在Android中使用带有网格布局的卡片视图创建回收者视图 - how to create recycler view using card view with grid layout in android 如何像 WhatsApp 聊天一样创建回收者视图 - How to create recycler view like WhatsApp chat 如何创建ExpandableStickyListHeaders Recycler View Android - How to create ExpandableStickyListHeaders Recycler view android 在回收器视图上创建点,如视图寻呼机 - Create dots on recycler view like view pager 如何在 android 中创建此水平回收器视图(或视图寻呼机)? - how can i create this horizontal recycler view(or view pager) in android? 如何在 Android 中构建像 Play Store 这样的自定义水平回收器视图? - How to build a custom horizontal recycler view like Play Store in Android? 如何在android中的Recycler View中更改图像(如单选按钮)? - how to change image in Recycler View in android (like a radio button)? 如何在 Android 中单击 Recycler View 并获取另一个 dataActivity 像 playstore? - How to click on Recycler View in Android and get Another dataActivity like playstore? 使用Android中的Recycler View作为片段创建文件浏览器和选择器? - Create a File Browser & Picker using Recycler View in Android as a Fragment? 如何在Android中的回收站视图中显示和隐藏视图? - How to show and hide view in recycler view in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM