Android版面在脸盒上将年龄与性别图标对齐

时间:2015-05-12 18:07:21

标签: android android-layout face-detection

enter image description here

我使用canvas for image在脸部检测区域和年龄文本上绘制矩形。

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

现在,我正在尝试将年龄显示的图片中的性别图标与年龄文字对齐。 其他问题是面部检测到的盒子可能很小,我怎样才能相应地调整TextView(图标+年龄)的大小。

    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 个答案:

答案 0 :(得分:0)

使用framelayout(图像上的relativelayout)并对齐它。然后以不同的方式调整图像大小,并将其与textview一起放在linearlayout中。

相关问题