开发者

how to set marginBottom in android listview or linearlayout Dynamically?

开发者 https://www.devze.com 2023-01-17 00:43 出处:网络
friends, i want to set layout_marginBottom using java code or dynamically in list view or linearlayout

friends,

i want to set layout_marginBottom using java code or dynamically

in list view or linearlayout

a开发者_JS百科ny one guide me how to achieve this?

any help would be appreciated.


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


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. @.@


You can use setMargins. Look at official documentation:

http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMargins(int,%20int,%20int,%20int)

Ger


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号