【问题标题】:How to set a drawable over an image view如何在图像视图上设置可绘制对象
【发布时间】:2013-04-28 06:44:12
【问题描述】:

我有一个drawbale,我想为这个gridView 中的每个图像将它放在一个gridView 中。 我的drawable就像一个正方形,但在边缘填充。因此,当我将此可绘制对象设置为图像的背景时,图像将覆盖我不需要的背景。 我需要这个drawable在图像的前面而不是在后面。

我的代码如下所示: 在此输入代码

   public class ComponentAlbums extends LinearLayout 
   {
   public ClassImageLoader imageLoader;
   public ComponentAlbums(Activity activity,Context context,WallPaperHD_Album item)
{
    super(context);
    imageLoader = new ClassImageLoader(activity);

    setOrientation(LinearLayout.HORIZONTAL);
    setBackgroundColor(Color.TRANSPARENT);

    LinearLayout.LayoutParams Params = new LinearLayout.LayoutParams(120, 120);
    ImageView imageView =  new ImageView(context);
    Params.gravity = Gravity.CENTER;
    imageView.setScaleType(ScaleType.FIT_XY);
    imageView.setPadding(10, 10, 10, 10);
    //imageView.setAdjustViewBounds(true);
    imageView.setBackgroundResource(R.drawable.frame_all_albums);//this line of     code iam using to set the drawable infront of the image.

请帮忙。

【问题讨论】:

    标签: android image android-layout gridview background


    【解决方案1】:

    一种反转背景和实际图像的简单方法。

    imageView.setImageResource(R.drawable.frame_all_albums);
    ...
    imageView.setBackgroundResource(actualImageBitmap);
    

    希望这会有所帮助。

    【讨论】:

    • 正如Aswin所说,图片内容可以与背景重叠。
    • 如果有人可以建议我其他选项,我真的需要解决这个问题
    • 您在尝试此代码时看到了什么?框架应该在实际图像的顶部。你看到了吗?
    • 我看到的是图像视图覆盖了可绘制的框架,因为可绘制不是一个完美的正方形,它是一个正方形,但下面的边缘有一个覆盖图像视图的弧希望我解释得很好
    • 我需要图像视图在可绘制对象内
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    相关资源
    最近更新 更多