LinearLayout下添加一个item

方式一:

定义一个线性布局:

向线性布局增加一个item:

cardPhotoListView.addView(new CardItemView(this),cardPhotoListView.getChildCount()-1);

自定义的视图

public class CardItemView extends LinearLayout {
	Button bt_delete;

	public CardItemView(Context context) {
		super(context);
		LayoutInflater.from(context).inflate(R.layout.userspecificinfor3_item,
				this);
	}

	public CardItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.userspecificinfor3_item,
				this);
	}

}

方式二:

@ViewById(R.id.cardPhotoListView)LinearLayout cardPhotoListView;

@Click(R.id.addMaterial)
	public void addMaterial() {
		// TODO 动态增加一个线性布局
		view = View.inflate(this, R.layout.userspecificinfor3_item, null);
		cardPhotoListView.addView(view);
		runUiThread();
	}

@UiThread
	public void runUiThread() {
		scrollView.fullScroll(ScrollView.FOCUS_DOWN);
	}



你可能感兴趣的:(android应用层)