【问题标题】:How can I set the layout:width of an object to (wrap_content + 10)?如何将对象的布局:宽度设置为(wrap_content + 10)?
【发布时间】:2013-07-02 20:52:04
【问题描述】:

我的 Android 应用视图中有一个按钮,layout:widthwrap_content 会根据按钮的内容自动调整宽度。

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

如何在 XML 中完成此操作?

【问题讨论】:

  • 为什么不使用android:layout_marginRight/Left

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


【解决方案1】:

你试过设置左右padding吗?

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

【讨论】:

  • 请注意,似乎有一些默认填充。我没有费心去查那个值是什么,但我只是把10dp放在两边作为例子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-14
  • 1970-01-01
相关资源
最近更新 更多