【发布时间】:2014-04-05 13:01:53
【问题描述】:
我正在尝试设置所有按钮的样式,但由于某种原因,我的样式并未影响它们的边距。 (它们紧挨着出现)但是在 layout.xml 上更改 layout_margin 确实有效。
这是我的代码:
<style name="Button" parent="@android:style/Widget.DeviceDefault.Button">
<item name="android:layout_margin">5dp</item>
<item name="android:background">@android:color/holo_orange_light</item>
</style>
这是我的布局:
<TableRow
android:layout_weight="1"
android:orientation="horizontal"
android:baselineAligned="false"
android:clickable="false"
android:layout_height="fill_parent"
android:layout_width="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="1"
android:id="@+id/button1"
android:layout_weight="0.06"
android:clickable="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="2"
android:id="@+id/button2"
android:layout_weight="0.06" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="3"
android:id="@+id/button3"
android:layout_weight="0.06"
android:layout_marginBottom="2dp" // This works
android:layout_marginTop="2dp" />
</TableRow>
//...
我做错了什么?
【问题讨论】:
-
请将 layout.xml 添加到您的问题中。
-
我刚刚添加了它。谢谢
-
在这种情况下,如果您将所有按钮放在水平线性布局中,问题将得到解决,但我遇到过类似的奇怪问题,TableLayout 尝试使用另一个布局来实现它。
-
@Liso22:您是否将您的样式分配给主题中的 buttonStyle 属性?类似
- @style/Button