如何在android中添加重叠透明背景的图像按钮?

时间:2014-07-15 06:46:10

标签: java android android-layout

这是我的设计,圆圈的三个部分是三个按钮。如何选择特定按钮?

我现在所做的是:

  • 剪切三个部分
  • 这三个部分分别设置为图像视图
  • 将它们整合为如下所示的圆形(中心圆形部分是另一个按钮)

然而,按钮后面的透明矩形区域重叠,我无法选择预期的按钮。

我的代码如下:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.butto);
    gp = new GPSTracker(ButtonhomeActivity.this);
    final NotificationManager mgr=
            (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    Log.e("dbfhb","fcxcv");
    se = (ImageView) findViewById(R.id.imageView4);
    ca = (ImageView) findViewById(R.id.imageView3);
    gr = (ImageView) findViewById(R.id.imageView2);
    ab= (ImageView) findViewById(R.id.imageView1);
    // show location button click event
    se.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_UP){
                Log.e("inside se ontouch","..");
                // Do what you want
                Log.e("inside onclick","...");
                // check if GPS enabled
                db= openOrCreateDatabase("Mydb", MODE_PRIVATE, null);
                if(gp.isGPSEnabled&&x==0){
                    Log.e("onclick gpsss","gpss");
                    la = gp.getLatitude();
                    lo = gp.getLongitude();
                    Log.e("lat",String.valueOf(la));
                    Log.e("lon",String.valueOf(lo));
                    // \n is for new line
                    Toast.makeText(ButtonhomeActivity.this, "Your Location is - \nLat: " + la + "\nLong: " + lo, Toast.LENGTH_LONG).show();
                    a=la + 0.1000;
                    b=la - 0.1000;
                    c1=lo + 0.1000;
                    d=lo - 0.1000;
                    Log.e("a",String.valueOf(a));
                    Log.e("b",String.valueOf(b));
                    Log.e("c1",String.valueOf(c1));
                    Log.e("d",String.valueOf(d));
                    Log.e("k ",String.valueOf(k));
                    // lon[]={77,66,55,77.5,77.012};
                    // lat[]={13.02,12,11,13.0456,22};
                    // for(int i=0;i<k;i++)
                    // {
                    // if((lat[i]>b) && (lat[i]<a) && (lon[i]>d) && (lon[i]<c1))
                    // {
                    try{
                        Log.e("before query","......");
                        //c = db.rawQuery("SELECT path FROM mytable where longi = '" +lon[i] + "' and lati = '" +lat[i] + "'" , null);
                        // c = db.rawQuery("SELECT path FROM mytable where longi > '"+d+ "'", null);
                        c=db.rawQuery("SELECT path,filename FROM mytable WHERE ( longi BETWEEN '"+d+"' AND '"+c1+"' ) AND ( lati BETWEEN '"+b+"' AND "+a+"') ",null);
                        c.moveToFirst();
                        Log.e("after query","..");
                        do{
                            String pat=c.getString(0);
                            String fil=c.getString(1);
                            path1[z]=pat;
                            fil1[z]=fil;
                            Log.e("path["+String.valueOf(z)+"]",path1[z]);
                            Log.e("fil1["+String.valueOf(z)+"]",fil1[z]);
                            z++;
                            // c.moveToNext();
                        }while(c.moveToNext());
                    }
                    catch(Exception e){Log.e("inside catch", "I shouldn't be here");}
                    Log.e(String.valueOf(z),"sizee of z");
                    // Toast.makeText(ButtonhomeActivity.this, "M in!",Toast.LENGTH_SHORT).show();
                    // Toast.makeText(NotificationAlert.this, "latitude "+la,Toast.LENGTH_SHORT).show();
                    // Toast.makeText(NotificationAlert.this, "longitude "+lo,Toast.LENGTH_SHORT).show();
                    if(path1[0]!=null){
                        Notification note=new Notification(R.drawable.ic_launcher,
                                                           "Notification!",
                                                           System.currentTimeMillis());
                        Intent i=new Intent(getBaseContext(), NotifyMessage.class);
                        i.putExtra("filepath", path1);
                        i.putExtra("filename",fil1);
                        i.putExtra("size",z);
                        // This pending intent will open after notification click
                        PendingIntent in = PendingIntent.getActivity(getBaseContext(), 0, i,PendingIntent.FLAG_ONE_SHOT);
                        note.setLatestEventInfo(getBaseContext(), "Memories Found!!!",
                                                "Click to view", in);
                        //After uncomment this line you will see number of notification arrived
                        //note.number=2;
                        mgr.notify(NOTIFY_ME_ID, note);
                    }
                    else
                    {
                        // Toast.makeText(ButtonhomeActivity.this, "m out!",Toast.LENGTH_SHORT).show();
                        // Toast.makeText(ButtonhomeActivity.this, "You are here for the first time!",Toast.LENGTH_SHORT).show();
                        Notification note=new Notification(R.drawable.ic_launcher,
                                                           "Notification!",
                                                           System.currentTimeMillis());
                        // This pending intent will open after notification click
                        PendingIntent in = PendingIntent.getActivity(getBaseContext(), 0,
                                                                     new Intent(getBaseContext(), ButtonhomeActivity.class),
                                                                     PendingIntent.FLAG_CANCEL_CURRENT);
                        note.setLatestEventInfo(getBaseContext(), "First Visit!!!",
                                                "click to create memories", in);
                        //After uncomment this line you will see number of notification arrived
                        //note.number=2;
                        mgr.notify(NOTIFY_ME_ID, note);
                    }
                }else{
                    gp.showSettingsAlert();
                    x=1;
                }
                return true;
            }
            return false;
        }
    });
    ca.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_UP){
                Log.e("inside ca ontouch","..");
                Log.e(String.valueOf(gp.canGetLocation),"isgpsenabled?...");
                if (gp.isGPSEnabled&&x==0){
                    //Do what you need if enabled...
                    // create class object
                    Intent i=new Intent(ButtonhomeActivity.this,NewMemoryActivity.class);
                    startActivity(i);
                }else{
                    //Do what you need if not enabled...
                    gp.showSettingsAlert();
                    //gp.isGPSEnabled=true;
                }
                return true;
            }
            Log.e("else part", "..");
            return false;
        }
    });
    gr.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_UP){
                Log.e("inside gr ontouch","..");
                // create class object
                Intent i=new Intent(ButtonhomeActivity.this,MainActivity.class);
                startActivity(i);
                return true;
            }
            return false;
        }
    });
    ab.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == MotionEvent.ACTION_UP){
                Log.e("inside ab ontouch","..");
                Intent i=new Intent(ButtonhomeActivity.this,AboutActivity.class);
                startActivity(i);
                return true;
            }
            return false;
        }
    });
}

对不起,我没有足够的声誉来发布图片!

有人会提出什么建议吗?

0 个答案:

没有答案
相关问题