weixin_36500438
weixin_36500438
2017-09-15 02:02

动态添加TextView背景图片,背景不改变大小

  • 需求
  • 图片
  • textview

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

    for (int i = 0; i < name.length; i++) {
        TextView textView = new TextView(getActivity());
        layoutParams.setMargins(10, 0, 0, 0);
        textView.setTextSize(20);
        textView.setBackgroundResource(R.drawable.im_number); //设置背景
        textView.setText(name[i]);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(layoutParams);
        llNumber.addView(textView);
                    需求是这样的,我要添加多个texitview而且要添加背景,但是添加背景不随textview的增多而变小,就显示不玩了,要怎么让背景图片跟随着变化?
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐