【发布时间】:2015-11-29 07:50:56
【问题描述】:
我的应用中有几十个按钮,样式继承自 Widget.AppCompat.Button。大多数按钮都有一个高度和状态变化动画。太棒了。
令人不快的是,一些按钮没有任何额外的好处。
这是其中一个工作按钮的示例
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?attr/defaultPadding"
android:minHeight="?attr/minTouchSize"
android:textAppearance="?attr/textAppearanceListRowLabel" />
这是一个按钮不起作用的 sn-p
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:minHeight="?attr/minTouchSize" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="?attr/minTouchSize" />
</LinearLayout>
这些在不同的布局上。我尝试过的事情:
- 我已将
button1添加到与按钮栏相同的布局文件中,button1仍然有效。 - 如果我从栏中的某个按钮中删除权重,它们将不起作用。
- 我已经尝试将我的按钮样式明确地放在每个按钮上
- 如果我将按钮栏设为垂直布局并使按钮与父级匹配,那么它可以工作!但这不是我想要的。
我想让这些按钮在水平布局中具有状态动画和高度。又名,我希望按钮占据相等的空间并彼此相邻放置两个。我怎样才能做到这一点?
我正在使用 appcompat 22.2.1
【问题讨论】:
-
您是否尝试在每个按钮上明确设置样式?
-
@Androider 不幸的是没有骰子:/
-
我已经尝试删除 minHeight attrs 并将您的代码放入活动的主要布局中,并且效果很好。这些参数可能有问题。
标签: android android-button android-appcompat android-elevation