[英]How to put images to ImageView with glide
i have some view on my screen that contains 3 ImageView
.我的屏幕上有一些包含 3 ImageView
视图。 I have another view (RecyclerView) that contain 30 icons.我有另一个包含 30 个图标的视图 (RecyclerView)。 I want that when I'm clicking on some icon from RV, it will be added to the container with 3 ImageView
to the first ImageView
.我希望当我单击 RV 中的某个图标时,它将被添加到容器中,并且将 3 ImageView
到第一个ImageView
。 If i click again on some other icon from RV, and ImageView
at index 0
is already used by previous clicked icon, this icon will be moved to index 1 and the new one will be added to the index 0.如果我再次单击 RV 中的某个其他图标,并且index 0
处的ImageView
已被先前单击的图标使用,则该图标将移动到索引 1,而新图标将添加到索引 0。
There is a code I have now: For now , it always add the icon the the index 0
.我现在有一个代码: For now ,它总是将图标添加到index 0
。
XML": XML”:
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:layout_height="match_parent">
<ImageView
android:id="@+id/historyContainer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/historyContainer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:id="@+id/historyContainer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
Fragment that contain the images:包含图像的片段:
private ArrayList<ImageView> historyItemsPH = new ArrayList<>();
historyItemsPH.add(mHistoryContainer1);
historyItemsPH.add(mHistoryContainer2);
historyItemsPH.add(mHistoryContainer3);
mLightsAdapter.setOnLightImageTouchListener(new LightsAdapter.OnLightImageTouchListener() {
@Override
public void onLightImageTouch(final int position, MotionEvent event, LightsAdapter.LightsViewHolder holder) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.removeSortFragment();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
mEmptyHistoryTXT.setVisibility(View.GONE);
Glide.with(getContext())
.load(mLightsArray.get(position).getLampImageUrl())
.override(150)
.into(historyItemsPH.get(0));
}
}
});
This will add to next every time, to do like you want you have to add more logic)这将添加到 next 每次,如您所愿,您必须添加更多逻辑)
int i = 0;
private ArrayList<ImageView> historyItemsPH = new ArrayList<>();
historyItemsPH.add(mHistoryContainer1);
historyItemsPH.add(mHistoryContainer2);
historyItemsPH.add(mHistoryContainer3);
mLightsAdapter.setOnLightImageTouchListener(new LightsAdapter.OnLightImageTouchListener() {
@Override
public void onLightImageTouch(final int position, MotionEvent event, LightsAdapter.LightsViewHolder holder) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.removeSortFragment();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
mEmptyHistoryTXT.setVisibility(View.GONE);
Glide.with(getContext())
.load(mLightsArray.get(position).getLampImageUrl())
.override(150)
.into(historyItemsPH.get(i));
i++;
if (i==3){
i = 0;
}
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.