简体   繁体   English

如何在Android中以编程方式删除图像视图周围的填充

[英]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. 我在一排有4个imageview,但我想根据响应进行可见和消失。 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 : 这将删除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. 因此,从getPaddingLeft(),getPaddingTop(),getPaddingRight()和getPaddingBottom()返回的值可能与此调用中设置的值不同。

Finally

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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