Reputation: 75
I'm working on a project that have events and the user view the event and choose to attend it or not, the question is.. I need to make a section of rounded images which is appear in the attached picture of the people who attend this event to be viewed by the event viewer!!
How can I do this?
Upvotes: 0
Views: 46
Reputation: 31
you can dynamically add views in your layout.
Here in code you are adding views in 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>
This your CircleImageView of users those are attending event.
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>
create a ViewHolder for your view
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;
}
Hope this will help :)
Upvotes: 1