how to set marginBottom in android listview or lin

2019-06-06 00:56发布

friends,

i want to set layout_marginBottom using java code or dynamically

in list view or linearlayout

any one guide me how to achieve this?

any help would be appreciated.

4条回答
祖国的老花朵
2楼-- · 2019-06-06 01:16

For ListView, there is much more simpler method to change margin by Programmatically

ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mListView
            .getLayoutParams();
    layoutParams.setMargins(0, 0, 0, 0);

But for LinearLayout, you can set margin from @UMAR answer. Have fun. @.@

查看更多
趁早两清
3楼-- · 2019-06-06 01:28

to change margin dynamically using the animation:

Animation animMarginChange = new Animation() {

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
           ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mListView
            .getLayoutParams();
                  layoutParams.setMargins(100, 0, 0, 0);
     }
};
 animMarginChange.setDuration(500); // in ms
 mListView.startAnimation(animMarginChange);
查看更多
\"骚年 ilove
5楼-- · 2019-06-06 01:41
ListView lst=getListView();

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                            LayoutParams.FILL_PARENT,
                            LayoutParams.FILL_PARENT
                        );
params.setMargins(0, 0, 0, 0); //left,top,right,bottom
lst.setLayoutParams(params);
查看更多
登录 后发表回答