4

我想实现Facebook的事件页面的外观,并且无法复制他们的三个按钮,说如果一个人要去一个事件。按钮的风格是添加未知属性 - Android

我试图做到这一点,

enter image description here

矿目前看起来是这样的,

enter image description here

这是按钮

<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> 

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

我最好猜测的是它可能与layout_weight属性有关。这可能会使按钮的宽度有一定的高度,如果是这种情况,那我该如何缩短按钮?

+2

而不是将layout_width设置为wrap_content给它一个特定的高度,然后你将实现你想要的效果 –

+0

尝试使用ImageButton并设置背景:android:src =“” – George

+1

按钮有'android:minHeight = 48dp'和'android:minWidth = 88dp'(on棒糖)。这包括任何填充。 –

回答

3

由于您正在应用背景item_left_button_background,因此必须是图像或选择器,其中包含图像,这些图像具有特定的高度。当您将按钮高度设置为wrap_content时,默认情况下会根据我的建议给出图片的高度,以便根据我的建议给出按钮的特定高度或根据您所需的尺寸创建背景图片

+1

这工作得很好。我没有想到背景具有一定的高度,因为它们是''。对于任何想要实现这一目标的人,我都会使用'height =“35dp”'来实现Facebook的外观。 –

+0

这是伟大的,如果我的答案帮助你可以接受它虽然:) –