2016-11-06 64 views
0

我正在研究一個有事件和用戶查看事件並選擇參加或不參加的項目,問題是......我需要製作一段圓形圖像,該圖像出現在人物的附圖中誰參加這個事件,由事件查看器查看!如何製作圓形圖像的部分android?

我該怎麼做?

Rounded Images Picture

回答

0

您可以動態地在佈局中添加視圖。

在這裏,你是在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; 
          } 

希望這將有助於:)