我正试图从顶部设置保证金。
RelativeLayout root = (RelativeLayout) view.findViewById(R.id.root);
listview = new PullListView(getActivity());
root.addView(listview);
如何设置列表视图的边距?
答案 0 :(得分:2)
RelativeLayout.LayoutParams relativeParams =(RelativeLayout.LayoutParams)relativeLayout.getLayoutParams();
relativeParams.setMargins(0, 80, 0, 0); // left, top, right, bottom
relativeLayout.setLayoutParams(relativeParams);
答案 1 :(得分:2)
使用LayoutParams
LayoutParams params=(LayoutParams) root.getLayoutParams();
params.leftMargin=0;
params.rightMargin=0;
params.rightMargin=0;
params.leftMargin=0;
root.setLayoutParams(params);