Android:如何通过编程将TextView设置为ImageView的顶部

时间:2014-12-20 10:21:34

标签: android

我已经动态创建了ImageView,我想通过编程方式将一个TextView设置为ImageView的顶部。

这是我的代码。

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    Bitmap bm = BitmapFactory.decodeResource(getResources(),
              R.drawable.ic_launcher);
    chatHead = new ImageView(this);
    num = new TextView(this);

    chatHead.setImageBitmap(getCircleBitmap(bm, 200));
    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;
windowManager.addView(chatHead, params);

1 个答案:

答案 0 :(得分:0)

同样使用相同的参数文本视图:

windowManager.addView(num, params);

它将在图像上显示textview。