简体   繁体   English

如何以编程方式减少EditText的边距和填充(android)

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

I have editText which by default leaves lots of space. 我有editText ,默认情况下会留很多空间。 I added backgroud for textView, cause editText backgroud is not possible. 我为textView添加了背景,因为不可能使用editText背景。

在此处输入图片说明

When I execute command: editText.setHeight(50); 当我执行命令时: editText.setHeight(50); of no matter what integer it gives me same result: 无论是什么整数,它都会给我相同的结果:

在此处输入图片说明

My text gets cropped. 我的文字被裁剪了。 I think somehow I need to reduce editText margins to fit my text here. 我认为我需要以某种方式减少editText的边距以适合此处的文本。

Main problem is that there is to much space between rows in first picture. 主要问题是第一张图片中的行之间有很多空间。

You can do like this 你可以这样

        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.

相关问题 Android - 减少EditText浮动标签填充/边距? - Android - reduce EditText floating label padding/margin? Android如何设置百分比填充/边距,以便EditText在任何一方都有10%的保证金? - Android how do I set a percentage padding/margin so EditText has 10% margin on either side? android:如何在EditText自定义背景和InputTextLayout标签之间设置边距/填充? - android: How to set margin/padding between EditText custom background and InputTextLayout Label? Android:如何删除底部的输入部分和edittext的底部空白之间的填充 - Android:how to remove the padding between the bottom input section and bottom margin of an edittext 如何以编程方式设置 EditText 布局边距? - How to set EditText layout margin programmatically? 如何以编程方式在 LinearLayout 中添加边距/填充? - How to add Margin/padding in LinearLayout programmatically? 如何以编程方式在 EditText 中设置填充? - How to set padding fixed in EditText programmatically? Android为内容(文本)设置边距/填充而不是容器(EditText) - Android set margin/padding for contents (text) instead of a container (EditText) Android:如何以编程方式突出显示EditText? - Android: How to highlight EditText programmatically? Android:如何在首选项中调整边距/填充? - Android: How to adjust Margin/Padding in Preference?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM