Search code examples
androidandroid-layoutface-detection

Android Layout align gender icon with age on facebox


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);

Solution

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