1

我有带有 ImageView 的 RelativeLayout。

我想点击图片并在顶部添加相同的图片。它必须是动态的,不调用 onCreate 方法。它是红色圆圈(透明 10% - *.png)

像这样:

http://i.stack.imgur.com/jGOhn.png

如何最好地做到这一点?

4

3 回答 3

1

每次只增加原图的alpha值。

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.my_picture);       
Paint paint = new Paint();
paint.setAlpha(CURRENT_VALUE);
canvas.drawBitmap(botmap, 0, 0, paint);

或直接使用 ImageView

ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);
于 2012-07-25T16:39:27.810 回答
0

How many times do you need to do this? There are a couple of ways depending upon your needs. First, if you only need to do it once. Put the image on top of the first image in your layout but set its visibility to invisible. Then when you click on the image, change the visibility to visible.

The second way if you need to do it repeatedly is to place the image view in a separate layout, use in the primary layout for the fist image then load the imageview using a layoutinflater in your code.

After the rest of your info, I moved my comment up here: Just increase the alpha value of the image.

于 2012-07-25T16:32:41.053 回答
0
public class Test extends Activity {


RelativeLayout relativeLayout;

 ImageView imageView1;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.text);

    relativeLayout=(RelativeLayout)findViewById(R.id.relativeLayout);



    imageView=(ImageView)findViewById(R.id.imageView);

    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            imageView1=new ImageView(Test.this);

            imageView1.setLayoutParams(imageView.getLayoutParams());



            //imageView1=imageView;

            imageView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub



                }
            });

            imageView1.setBackgroundResource(R.drawable.arrow1);
            relativeLayout.addView(imageView1);
            Toast.makeText(Test.this, "NEW IMAGE", 1).show();
            Toast.makeText(Test.this, "OLD IMAGE", 1).show();

            imageView.setVisibility(View.GONE);

            imageView=null;


        }
    } 
    );

XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:background="@drawable/aboutus_h" />

</RelativeLayout>

这将帮助您完成工作。

于 2012-07-25T16:50:59.057 回答