Android如何在Relativelayout中设置保证金

时间:2014-11-18 07:53:06

标签: android android-layout android-relativelayout

我正试图从顶部设置保证金。

RelativeLayout root = (RelativeLayout) view.findViewById(R.id.root);        
    listview = new PullListView(getActivity());
    root.addView(listview);

如何设置列表视图的边距?

2 个答案:

答案 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);