动态添加布局

		RelativeLayout layout = new RelativeLayout(container.getContext());
	    TextView Tv_title = new TextView(container.getContext());
        ViewGroup.MarginLayoutParams mp3 = new ViewGroup.MarginLayoutParams(1000,100);  //item的宽高
        mp3.setMargins(0, 30, 0, 0);//分别是margin_top那四个属性
        RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(mp3);
        lp3.addRule(RelativeLayout.CENTER_HORIZONTAL);
        Tv_title.setLayoutParams(lp3);
        Tv_title.setGravity(Gravity.CENTER);
        Tv_title.setText(activityMessages.get(position).getTitle());
        Tv_title.setTextColor(Color.BLACK);
        Tv_title.setTextSize(20);
        layout.addView(Tv_title);
发布了57 篇原创文章 · 获赞 3 · 访问量 6222

猜你喜欢

转载自blog.csdn.net/qq_39830579/article/details/87305789