簡體   English   中英

如何以編程方式減少EditText的邊距和填充(android)

[英]How to decrease margin and padding of editText programmatically (android)

我有editText ,默認情況下會留很多空間。 我為textView添加了背景,因為不可能使用editText背景。

在此處輸入圖片說明

當我執行命令時: editText.setHeight(50); 無論是什么整數,它都會給我相同的結果:

在此處輸入圖片說明

我的文字被裁剪了。 我認為我需要以某種方式減少editText的邊距以適合此處的文本。

主要問題是第一張圖片中的行之間有很多空間。

你可以這樣

        int reducedValue =5;

        editText .setPadding(editText .getPaddingLeft()-reducedValue,
                editText .getPaddingTop()-reducedValue,
                editText .getPaddingRight()-reducedValue,
                editText .getPaddingBottom()-reducedValue);

        editText.setCompoundDrawablesWithIntrinsicBounds(editText .getPaddingLeft()-reducedValue,
                editText .getPaddingTop()-reducedValue,
                editText .getPaddingRight()-reducedValue,
                editText .getPaddingBottom()-reducedValue);

暫無
暫無

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

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