如何制作圆形图像部分android?

时间:2016-11-06 09:57:50

标签: android xml image android-layout android-studio

我正在研究一个有事件的项目,用户查看事件并选择是否参加,问题是..我需要制作一部分圆形图像,这些图像出现在附图中参加此活动的人将被活动观众观看!!

我该怎么做?

Rounded Images Picture

1 个答案:

答案 0 :(得分:1)

您可以在布局中动态添加视图。

在代码中,您将在LinearLayout layout_list_view中添加视图 your_activity.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >

    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/layout_list_view"
                android:gravity="center"
                 android:layout_marginLeft="20dp"       
                android:orientation="horizontal">
                </LinearLayout>

                </RelativeLayout>

这是您参加活动的用户的CircleImageView add_view.xml

            <?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="match_parent"
                android:layout_height="60dp">
             <com.leafwearables.saferkids.customViews.AppCompatCircleImageView
                    android:id="@+id/imageView"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="-20dp"
                    app:civ_border_color="@color/white"
                    app:civ_border_width="1dp"
                    app:srcCompat="@drawable/temp" />

                    </RelativeLayout>

为您的视图创建ViewHolder

            public class UserVH extends RecyclerView.ViewHolder {

             public UserVH(View inflate, int ind) {
                    super(inflate);
                    index = ind;
                    baseView = itemView;
                    initialize(itemView);
                }

                 private void initialize(View itemView) {
                    imageView = (AppCompatCircleImageView) itemView.findViewById(R.id.imageView);

                }


                public int getIndex() {
                    return index;
                }

                public View getBaseView() {
                    return baseView;
                }

            }

YourActivty.class

         private void addUsersView() {

                        LinearLayout user_list_view = (LinearLayout) findViewById(R.id.layout_list_view);
                        final UserVH[] views = new UserVH[userList.size()];
                         for (int i = 0; i < views.length; i++) {
                         views[i] = new UserVH(LayoutInflater.from(this).inflate(R.layout.add_view, null), i);
                                   try {
                                        File profileFile = new File(getProfileDir(this), child.getDeviceId());
                                        if (profileFile.exists()) {
                                        Bitmap bitmap = BitmapFactory.decodeFile(profileFile.getPath());
                                            views[i].imageView.setImageBitmap(bitmap);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    user_list_view.addView(views[i].getBaseView(), -1, 60);

                                    }

                        } 

                          public  File getProfileDir(Context context) {
                                File fileProfile = new File(context.getFilesDir(), "USERS");
                                fileProfile.mkdir();
                                return fileProfile;
                            }

希望这会有所帮助:)