0

enter image description here

I used canvas for image to draw rectangle on face detected area and age text on top.

Paint paint = new Paint();
paint.setTextAlign(Paint.Align.CENTER);
Canvas canvas = new Canvas(bitmap);
canvas.drawRect(left, top, left + width, top + height, paint);
canvas.drawText(myText, left + width / 2,(float) (top - 10), paint);

Now I'm trying to align gender icon with age text inside image where age is showing. Other problem is face detected box might be small, how can I re-size my TextView(icon + age) accordingly.

    TextView txtView=new TextView(getApplicationContext());
    txtView.setText(String.valueOf((int)json.getDouble("age")));
    txtView.setTextColor(getResources().getColor(R.color.red));
    txtView.setBackgroundColor(getResources().getColor(R.color.grey_dark));
    if (json.getDouble("sex") >= 0.5) {
        txtView.setCompoundDrawablesWithIntrinsicBounds( R.drawable.maleicon, 0, 0, 0);
    } else {
        txtView.setCompoundDrawablesWithIntrinsicBounds( R.drawable.femaleicon, 0, 0, 0);
    }
    LayoutParams layoutParams = new LayoutParams(150, 110);
    txtView.setLayoutParams(layoutParams);
    LL.addView(txtView);

1 Answers1

0

use framelayout ( relativelayout over image) and align it . then resize the image differently and put it in linearlayout with textview.

Shreyans jain
  • 559
  • 6
  • 18
  • Thanks, I tried by following your instruction, it still not aligned well http://tinypic.com/r/16i8x7o/8 kindly give me a tip to align – Bilal Ameer May 13 '15 at 02:12
  • In relativelayout you can align linearlayout(age+gender icon) over the canvas box view. use .............android:layout_above http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_above – Shreyans jain May 13 '15 at 09:25