In my project, I'd like to have two Button
elements in a LinearLayout
without space between them.
I've tried to set padding
and margin
to 0dp
, to remove style
and to remove ScrollView
but nothing works. I can't figure out a way to remove the space between buttons. Do you have some ideas?
My XML is:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The first child in the layout is for the main Activity UI-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"
android:orientation="vertical"
>
</LinearLayout>
<!-- Side navigation drawer UI -->
<ScrollView
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee"
android:clickable="true"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical" android:padding="0dp" >
<Button
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/agenda"
android:drawableLeft="@drawable/agenda_icon"
android:textAllCaps="false"
android:gravity="left|center_vertical"
android:drawablePadding="5dp"
android:layout_margin="0dp"
android:padding="0dp"
/>
<Button
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/day"
android:drawableLeft="@drawable/agenda_icon"
android:textAllCaps="false"
android:gravity="left|center_vertical"
android:drawablePadding="5dp"
android:layout_margin="0dp"
android:padding="0dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/month"
android:drawableLeft="@drawable/agenda_icon"
android:textAllCaps="false"
android:gravity="left|center_vertical"
android:drawablePadding="5dp"
android:layout_margin="0dp"
android:padding="0dp"
style="?android:attr/borderlessButtonStyle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
But the result is (I've touch the last two buttons to show the button background):
Setting padding
of each Button to 0 (@aga answer) doesn't solve my problem :(
Try changing the color of the button, because the default interface of the button which is native to android is center-fitted to make it look cool.
Change the background color of the button to match the color of the layout in which it is placed, then we will get the real size of the button. In your case
android:background="#000"
Use this since it does not use the style it may get rid of some issues by setting the width to a hard coded size and by uses default paddings
<Button
android:id="@+id/btn_overtime"
android:layout_width="310sp"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:text="Overtime"
android:textSize="20sp"
android:textStyle="bold" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.