我有一个listview,我希望列表视图中的项目有自己的边距。我在下面给了getView()方法我的适配器代码。
public View getView(int position, View convertView, ViewGroup parent) {
Message msg = getItem(position);
TextMessageView view = new TextMessageView(getContext(), flag);
flag = !flag;
view.setMessage(msg);
view.setMinimumHeight(50);
if(flag) {
view.setGravity(Gravity.RIGHT);
} else {
view.setGravity(Gravity.LEFT);
}
return view;
}
我想通过代码设置保证金。有可能吗?
答案 0 :(得分:0)
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
params.setMargins(left, top, right, bottom); //substitute parameters for left, top, right, bottom
view.setLayoutParams(params);
可能会以某种方式复制到这个......