简体   繁体   中英

how to delete padding around image view programmatically in android

I have 4 imageview in one rows but i wanted to visible and gone need to do based on response. so how to remove unused space which i hardcoded layout.

<ImageView
        android:id="@+id/imgFacebookUrl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/facebook_login_guest"
        app:layout_anchor="@id/appbar"
        android:visibility="gone"
        app:layout_anchorGravity="bottom|center" />

    <ImageView
        android:id="@+id/imgLinkdinUrl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="200dp"
        android:src="@drawable/icon_linkdin"
        app:layout_anchor="@id/appbar"
        android:visibility="gone"
        app:layout_anchorGravity="bottom|center" />

This deletes all paddings (all sides) for your imgLinkdinUrl ImageView :

ImageView linkedInUrlImage = (ImageView) findViewById(R.id.imgLinkdinUrl);
linkedInUrlImage.setPadding(0, 0, 0, 0);
public void setPadding (int left, int top, int right, int bottom)

Sets the padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom() may be different from the values set in this call.

Finally

ImageView ImageViewObj = (ImageView) findViewById(R.id.imgLinkdinUrl);
ImageViewObj.setPadding(0, 0, 0, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM