Note that there are some explanatory texts on larger screens.

plurals
  1. POCentering borderless buttons between a horizontal line
    primarykey
    data
    text
    <p>I am trying my attempt at borders buttons in android. Currently I have an activity where the buttons look like this:</p> <p><img src="https://i.stack.imgur.com/khZZC.png" alt="Screenshot"></p> <p>The buttons are separated by a vertical line and I would like them centered in their "columns" which are created by the vertical lines:</p> <p>Here is my xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; </code></pre> <p></p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:orientation="vertical" android:background="@drawable/bg_card"&gt; &lt;!-- Card Contents go here --&gt; &lt;TextView android:id="@+id/breweryTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:textSize="20sp" android:textStyle = "bold" android:padding="5dip" &gt; &lt;/TextView&gt; &lt;/LinearLayout &gt; &lt;/FrameLayout&gt; &lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:orientation="vertical" android:background="@drawable/bg_card"&gt; &lt;!-- Card Contents go here --&gt; &lt;ImageView android:id="@+id/breweryImage" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="10dip"/&gt; &lt;/LinearLayout &gt; &lt;/FrameLayout&gt; &lt;TableLayout android:id="@+id/tableLayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:shrinkColumns="*" android:stretchColumns="*"&gt; &lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:orientation="vertical" android:background="@drawable/bg_card"&gt; &lt;!-- Card Contents go here --&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;TextView android:id="@+id/breweryEstablished" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:text="Year Established: " android:textSize="15sp" android:textStyle = "bold" android:padding="5dip" &gt; &lt;/TextView&gt; &lt;TextView android:id="@+id/yearTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:text="" android:textSize="15sp" android:padding="5dip" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout &gt; &lt;/FrameLayout&gt; &lt;/TableLayout&gt; &lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:orientation="vertical" android:background="@drawable/bg_card"&gt; &lt;!-- Card Contents go here --&gt; &lt;TextView android:id="@+id/beerDescriptionTitle2" android:textStyle = "bold" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:textSize="15sp" android:text="Description:" android:padding="5dip" &gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/breweryDescription" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:textSize="15sp" android:padding="5dip" &gt;&lt;/TextView&gt; &lt;/LinearLayout &gt; &lt;/FrameLayout&gt; &lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:orientation="vertical" android:background="@drawable/bg_card"&gt; &lt;TextView android:id="@+id/discoverLabel" android:textStyle = "bold" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:textSize="15sp" android:text="Discover:" android:padding="5dip" &gt;&lt;/TextView&gt; &lt;!-- Card Contents go here --&gt; &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="center" android:orientation="horizontal" &gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="All Beers" android:id="@+id/button" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getAllBeers" android:layout_centerHorizontal="true" android:layout_weight="1"/&gt; &lt;View android:id="@+id/ViewColorPickerHelper" android:layout_width="1dip" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="?android:attr/dividerVertical" android:layout_centerHorizontal="true"/&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Top Beers" android:id="@+id/button2" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getTopBeers" android:layout_centerHorizontal="true" android:layout_weight="1" /&gt; &lt;View android:id="@+id/ViewColorPickerHelper" android:layout_width="1dip" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="?android:attr/dividerVertical" android:layout_centerHorizontal="true"/&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your Beers" android:id="@+id/button2" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getYourTopBeers" android:layout_centerHorizontal="true" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; &lt;Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Directions to Brewery" android:id="@+id/button2" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getDirections" /&gt; &lt;/LinearLayout &gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>I have tried playing with the layout width and gravity but still no luck.</p> <p>Update:</p> <p>I tried the recent suggestions and I now have them all centered correctly but it just makes everything super long and I can not see the third last button.</p> <pre><code>&lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:orientation="vertical" android:background="@drawable/bg_card"&gt; &lt;TextView android:id="@+id/discoverLabel" android:textStyle = "bold" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:textSize="15sp" android:text="Discover:" android:padding="5dip" &gt;&lt;/TextView&gt; &lt;!-- Card Contents go here --&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:orientation="horizontal" &gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:text="All Beers" android:id="@+id/button" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getAllBeers" android:layout_centerHorizontal="true" android:layout_weight="0.33"/&gt; &lt;View android:id="@+id/ViewColorPickerHelper" android:layout_width="1dip" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="?android:attr/dividerVertical" android:layout_centerHorizontal="true"/&gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:text="Top Beers" android:id="@+id/button2" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getTopBeers" android:layout_weight="0.33" /&gt; &lt;View android:id="@+id/ViewColorPickerHelper" android:layout_width="1dip" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="?android:attr/dividerVertical" android:layout_centerHorizontal="true"/&gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:text="Your Beers" android:id="@+id/button2" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getYourTopBeers" android:layout_centerHorizontal="true" android:layout_weight="0.33" /&gt; &lt;/LinearLayout&gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:text="Directions to Brewery" android:id="@+id/button2" style="?android:attr/borderlessButtonStyle" android:textColor="@color/orange" android:textStyle="bold" android:onClick="getDirections" /&gt; &lt;/LinearLayout &gt; &lt;/FrameLayout&gt; </code></pre> <p><img src="https://i.stack.imgur.com/1r8pG.png" alt="enter image description here"></p> <p>I also tried changing the linear layout its in to wrap-content for height but that didnt fix it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload