android - 如何设置布局 :width of an object to (wrap_content + 10)?

标签 android android-layout android-xml android-studio

我的 Android 应用程序 View 中有一个按钮,其 layout:widthwrap_content,它会根据按钮的内容自动调整宽度。

我想对按钮应用一些左右填充,所以我想在 wrap_content 的值之上额外添加 10px 左右。

我如何在 XML 中完成此操作?

最佳答案

你有没有试过设置左右padding

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
/>

关于android - 如何设置布局 :width of an object to (wrap_content + 10)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17435669/

相关文章:

android - 如何以编程方式在 Android 中创建和读取 WEP/EAP WiFi 配置?

java - 在android中计算圆周围的点

android - Imageview缩放保持高度固定和宽度可变

android - 将自定义布局添加到工具栏

java - 不在android studio中显示styles.xml

java - 在 SettingsActivity 中未定义 findPreference

java - 解析查询获取数据到列表

android-layout - Android 资源使用 XHDPI、HDPI

android - 错误 : Inflating class com. google.android.material.textfield.TextInputLayout

android - 当View有边距定位时,如何获取View的X坐标?