android - How to layout three buttons evenly located under LinearLayout? -
i have 3 buttons need located in 1 line @ bottom of screen. below code in activity xml. in order make 3 button takes space, wrap each of them inside linearlayout , set layout android:layout_weight
1 , android:layout_gravity
center.
<linearlayout android:layout_width="match_parent" android:layout_height="90px" android:background="#88104502" android:orientation="horizontal"> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="horizontal" android:layout_weight="1"> <button android:id="@+id/goback" android:layout_width="70px" android:layout_height="80px" android:gravity="center" android:background="@drawable/back" android:onclick="tohomepage" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="horizontal" android:layout_weight="1"> <button android:id="@+id/findplant" android:layout_width="70px" android:layout_height="80px" android:gravity="center" android:background="@drawable/flowr" android:onclick="toimagepage" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:orientation="horizontal" android:layout_gravity="center" android:layout_weight="1"> <button android:id="@+id/plantlist" android:layout_width="70px" android:layout_height="80px" android:gravity="center" android:background="@drawable/list" /> </linearlayout> </linearlayout>
but button not located in center of linearlayout. below screenshot:
you can see each button located on left of linearlayout. how make them center located?
try this. use code give gravity linear layout.if not want use of linearlayout use 1 main linearlayout , give equal weight 3 buttons.
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="90px" android:background="#88104502" android:orientation="horizontal"> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="horizontal" android:gravity="center" android:layout_weight="1"> <button android:id="@+id/goback" android:layout_width="70px" android:layout_height="80px" android:gravity="center" android:background="@mipmap/ic_launcher" android:onclick="tohomepage" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" android:orientation="horizontal" android:layout_weight="1"> <button android:id="@+id/findplant" android:layout_width="70px" android:layout_height="80px" android:gravity="center" android:background="@mipmap/ic_launcher" android:onclick="toimagepage" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:orientation="horizontal" android:layout_gravity="center" android:gravity="center" android:layout_weight="1"> <button android:id="@+id/plantlist" android:layout_width="70px" android:layout_height="80px" android:background="@mipmap/ic_launcher" /> </linearlayout>
Comments
Post a Comment