【问题标题】:How to make Section of rounded images android?如何制作圆形图像部分android?
【发布时间】:2016-11-06 09:57:49
【问题描述】:

我正在开展一个有活动的项目,用户查看活动并选择参加与否,问题是.. 我需要制作一段圆形图像,该图像显示在附件的图片中参加此活动的人将被活动查看者查看!

我该怎么做?

【问题讨论】:

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


    【解决方案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;
                                }
    

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-24
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 2014-05-21
      • 2020-02-21
      相关资源
      最近更新 更多