【问题标题】:Button's style is adding unknown attribute - AndroidButton 的样式正在添加未知属性 - Android
【发布时间】:2015-05-12 05:27:27
【问题描述】:

我正在尝试实现 Facebook 活动页面的外观,但无法复制他们的三个按钮,这些按钮表示一个人是否要去参加活动。

我正在努力实现这一目标,

我的目前看起来像这样,

这是按钮的 XML

    <LinearLayout
        android:id="@+id/button_holder"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:paddingBottom="10dp">

        <Button
            android:id="@+id/button_going"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="14sp"
            android:textColor="@color/secondary_text"
            android:text="Going"
            android:background="@drawable/item_left_button_background"/>

        <Button
            android:id="@+id/button_maybe"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="14sp"
            android:textColor="@color/secondary_text"
            android:text="Maybe"
            android:background="@drawable/item_middle_button_background"/>

        <Button
            android:id="@+id/button_decline"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="14sp"
            android:textColor="@color/secondary_text"
            android:text="Decline"
            android:background="@drawable/item_right_button_background"/>

    </LinearLayout>

我不知道按钮上方和下方的额外PaddingMargin 来自哪里。我在按钮上尝试了android:padding="0dp"android:layout_margin="0dp",但没有效果。

我最好的猜测是它可能与layout_weight 属性有关。这可能会根据按钮的宽度为按钮提供一定的高度,如果是这种情况,那么我怎样才能使按钮更短?

【问题讨论】:

  • 而不是给 layout_width 作为 wrap_content 给它一个特定的高度然后你会实现你想要的
  • 尝试使用 ImageButton 并使用 :android:src="" 设置背景
  • 按钮有android:minHeight=48dpandroid:minWidth=88dp(在棒棒糖上)。这包括任何填充。

标签: android android-layout android-button android-layout-weight


【解决方案1】:

当您应用背景item_left_button_background 时,它必须是包含图像的图像或选择器,这些图像具有特定的高度。当您将按钮高度指定为wrap_content 时,默认情况下将采用图像的高度,以便根据我的建议为按钮指定特定高度或根据您需要的尺寸创建背景图像

【讨论】:

  • 这很好用。我没有考虑背景有固定高度这一事实,因为它们是&lt;layer-list&gt;。对于任何想要实现这一点的人,我使用height="35dp" 来实现 Facebook 外观。
  • 那太好了,如果我的回答对你有帮助的话你可以接受:)
猜你喜欢
  • 1970-01-01
  • 2016-07-02
  • 2019-10-31
  • 1970-01-01
  • 2019-03-22
  • 2019-05-03
  • 2011-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多