选择图像视图时如何在其顶部添加透明图像?
How to add a transparent image on the top of the image view when it is selected?
我有一组连续的图像视图,当用户点击图像时,背景变得越来越changed.I想在我的图像视图的顶部添加一个带有小勾的透明图像中间表示选中。
final ImageView iv_image=new ImageView(this);
LayoutParams iv_image_params=new LayoutParams(
Math.round(100*multiplier),
Math.round(100*multiplier));
iv_image_params.setMargins(5, 5, 10, 5);
iv_image.setId(Integer.parseInt(id));
try {
Bitmap bmp = BitmapFactory.decodeFile(DashBoard.file_path+image);
iv_image.setImageBitmap(bmp);
iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
iv_image.setSelected(false);
} catch (Exception e) {
}
iv_image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (iv_image.isSelected()==false) {
iv_image.setBackground(getResources().getDrawable(R.drawable.border_only_image_based));
iv_image.setSelected(true);
} else {
iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
iv_image.setSelected(false);
}
}
});
ll_view.addView(iv_image, iv_image_params);
*border_only_image_based:是我的选择器,我只是在其中为图像视图设置白色边框以指示它已被选中。
普通图像:
我想在该图像视图顶部显示的图像:
像下面这样的内容应该会有帮助。
<RelativeLayout
android:id="@+id/rl_profile_pic_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/img_profile_pic_non_editable"
android:layout_width="110dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:background="@drawable/your_actual image"
android:scaleType="center" />
<ImageView
android:id="@+id/img_camera_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:src="@drawable/your_tick_icon"
android:visibility="gone" />
</RelativeLayout>
第一个图像视图是您的实际图像。第二张图片是您要放置在其上方的刻度线。添加一个 clicklistener 使刻度线可见或不可见。此代码基于我的要求。请根据需要修改其他属性。
尝试使用刻度图像作为图标大小,如36x36,48x48,72x72,96x96
我有一组连续的图像视图,当用户点击图像时,背景变得越来越changed.I想在我的图像视图的顶部添加一个带有小勾的透明图像中间表示选中。
final ImageView iv_image=new ImageView(this);
LayoutParams iv_image_params=new LayoutParams(
Math.round(100*multiplier),
Math.round(100*multiplier));
iv_image_params.setMargins(5, 5, 10, 5);
iv_image.setId(Integer.parseInt(id));
try {
Bitmap bmp = BitmapFactory.decodeFile(DashBoard.file_path+image);
iv_image.setImageBitmap(bmp);
iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
iv_image.setSelected(false);
} catch (Exception e) {
}
iv_image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (iv_image.isSelected()==false) {
iv_image.setBackground(getResources().getDrawable(R.drawable.border_only_image_based));
iv_image.setSelected(true);
} else {
iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
iv_image.setSelected(false);
}
}
});
ll_view.addView(iv_image, iv_image_params);
*border_only_image_based:是我的选择器,我只是在其中为图像视图设置白色边框以指示它已被选中。
普通图像:
我想在该图像视图顶部显示的图像:
像下面这样的内容应该会有帮助。
<RelativeLayout
android:id="@+id/rl_profile_pic_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/img_profile_pic_non_editable"
android:layout_width="110dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:background="@drawable/your_actual image"
android:scaleType="center" />
<ImageView
android:id="@+id/img_camera_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:src="@drawable/your_tick_icon"
android:visibility="gone" />
</RelativeLayout>
第一个图像视图是您的实际图像。第二张图片是您要放置在其上方的刻度线。添加一个 clicklistener 使刻度线可见或不可见。此代码基于我的要求。请根据需要修改其他属性。
尝试使用刻度图像作为图标大小,如36x36,48x48,72x72,96x96