You need to use a relative layout to place the background image using ImageView as follows:
activity_layout.xml
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg"/> </RelativeLayout>
after that you need to create a separate XML file inside drawable, which defines each shape as accurately as possible. Read more about this here: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
the sample xml form file will be like
extractor hood / myshape1.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <stroke android:width="2dp" android:color="#FFFFFF" /> <corners android:radius="5dp" /> <gradient android:angle="270" android:centerColor="#6E7FFF" android:endColor="#142FFC" android:startColor="#BAC2FF" /> </shape>
Finally, after creating all your shapes, you can add them to your activity_layout.xml file as follows:
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="80dp" android:layout_margin="20dp" android:background="@drawable/myshape1" android:orientation="vertical" android:padding="5dp" > </RelativeLayout>
make sure that the created forms are as transparent as possible and attach onClick handlers to them to perform the assigned tasks.
EDIT:
Based on your comment, there is another way to do this by overriding the OnTouch listener, grabbing a pixel from the bitmap and determining its color.
imageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN){ ImageView imageView = (ImageView) v; Bitmap bitmap =((BitmapDrawable)imageView.getDrawable()).getBitmap(); int pixel = bitmap.getPixel(event.getX(),event.getY()); int redValue = Color.red(pixel); int blueValue = Color.blue(pixel); int greenValue = Color.green(pixel);
Tarek source share