簡體   English   中英

Android:“圖像”按鈕的頁邊距過大

[英]Android : Image button has unwanted margin

我的Android項目中有一些圖片按鈕。 但是它們有一些像這樣的圖片空白邊緣(我從真實設備上取了這張照片):

在此處輸入圖片說明

如何刪除它們? 我使用了這段代碼,但沒有任何效果。

 ib.setAdjustViewBounds(true);     

圖像按鈕只是在Java中定義的,而我在xml中沒有。

 ib = new ImageButton(this);
 ib.setImageResource(R.drawable.image);
 ib.setAdjustViewBounds(true);
 ib.setLayoutParams(ibrllp);

如何刪除此額外的灰階余量?

設置您的圖像按鈕背景為空。 例如。

ib.setBackground(null);

對我來說效果很好,默認情況下它的背景為空白。

在代碼中:

ImageButton imageButton = ImageButton.class.cast(rootView.findViewById(R.id.imageButton));
imageButton.setBackground(null);

在xml文件中:

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:background="@null" />

“ rootView”是誇大為片段或活動的布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM