android - Buttons with background image not next to each other? -


i new android. tried fill_parent,match_parent instead of wrap_content. want 2 buttons background image in 1 row. tried using weightsum="2" , each button having layout_weigh="1". not working . please suggest going wrong. xml file below

<linearlayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="vertical"      android:weightsum="2">       <button          android:id="@+id/button5"          style="?android:attr/borderlessbuttonstyle"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_marginleft="4dp"          android:layout_marginstart="4dp"          android:layout_margintop="4dp"          android:layout_weight="1"          android:background="@drawable/theatre"          android:gravity="bottom|center_horizontal"          android:paddingbottom="18dp"          android:text="theatre"          android:textcolor="@color/green" />       <button          android:id="@+id/butt3"          style="?android:attr/borderlessbuttonstyle"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_marginend="4dp"          android:layout_marginright="4dp"          android:layout_margintop="4dp"          android:layout_weight="1"          android:background="@drawable/hospital_icon"          android:gravity="bottom|center_horizontal"          android:paddingbottom="18dp"          android:text="hospital"          android:textcolor="@color/green" />       <button          android:id="@+id/button1"          android:layout_weight="1"          style="?android:attr/borderlessbuttonstyle"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_marginleft="4dp"          android:layout_marginstart="4dp"          android:layout_margintop="4dp"          android:background="@drawable/pubs"          android:gravity="bottom|center_horizontal"          android:paddingbottom="18dp"          android:text="pubs"          android:textcolor="@color/green" />      <button         android:id="@+id/button2"         android:layout_width="wrap_content"         android:layout_weight="1"         android:layout_height="wrap_content"         style="?android:attr/borderlessbuttonstyle"         android:layout_gravity="left|top"         android:layout_margintop="4dp"         android:layout_row="1"         android:background="@drawable/hotel"         android:gravity="bottom|center_horizontal"         android:paddingbottom="18dp"         android:layout_marginstart="4dp"         android:layout_marginleft="4dp"         android:text="hotels"         android:textcolor="@color/green" />      <button         android:id="@+id/button6"         style="?android:attr/borderlessbuttonstyle"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginend="4dp"         android:layout_marginright="4dp"         android:layout_margintop="4dp"         android:layout_weight="1"         android:background="@drawable/mall"         android:gravity="bottom|center_horizontal"         android:paddingbottom="18dp"         android:text="malls"         android:textcolor="@color/green" />      <button         android:id="@+id/button4"         style="?android:attr/borderlessbuttonstyle"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginend="4dp"         android:layout_marginright="4dp"         android:layout_margintop="4dp"         android:background="@drawable/monum"         android:gravity="bottom|center_horizontal"         android:paddingbottom="18dp"         android:text="monuments"         android:textcolor="@color/green" />      <button         android:id="@+id/button7"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="left|center_vertical"         android:text="expense calculator"         android:textcolor="@color/green" /> </linearlayout> 

you can try this,

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical" >      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:weightsum="2" >          <button             android:id="@+id/button5"             style="?android:attr/borderlessbuttonstyle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_marginleft="4dp"             android:layout_marginstart="4dp"             android:layout_margintop="4dp"             android:layout_weight="1"             android:background="@drawable/ic_launcher"             android:gravity="bottom|center_horizontal"             android:paddingbottom="18dp"             android:text="theatre"             android:textcolor="@color/cream_dark" />          <button             android:id="@+id/butt3"             style="?android:attr/borderlessbuttonstyle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_marginend="4dp"             android:layout_marginright="4dp"             android:layout_margintop="4dp"             android:layout_weight="1"             android:background="@drawable/ic_launcher"             android:gravity="bottom|center_horizontal"             android:paddingbottom="18dp"             android:text="hospital"             android:textcolor="@color/cream_dark" />     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:weightsum="2" >          <button             android:id="@+id/button1"             style="?android:attr/borderlessbuttonstyle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_marginleft="4dp"             android:layout_marginstart="4dp"             android:layout_margintop="4dp"             android:layout_weight="1"             android:background="@drawable/ic_launcher"             android:gravity="bottom|center_horizontal"             android:paddingbottom="18dp"             android:text="pubs"             android:textcolor="@color/cream_dark" />          <button             android:id="@+id/button2"             style="?android:attr/borderlessbuttonstyle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="left|top"             android:layout_marginleft="4dp"             android:layout_marginstart="4dp"             android:layout_margintop="4dp"             android:layout_row="1"             android:layout_weight="1"             android:background="@drawable/ic_launcher"             android:gravity="bottom|center_horizontal"             android:paddingbottom="18dp"             android:text="hotels"             android:textcolor="@color/cream_dark" />     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:weightsum="2" >          <button             android:id="@+id/button6"             style="?android:attr/borderlessbuttonstyle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_marginend="4dp"             android:layout_marginright="4dp"             android:layout_margintop="4dp"             android:layout_weight="1"             android:background="@drawable/ic_launcher"             android:gravity="bottom|center_horizontal"             android:paddingbottom="18dp"             android:text="malls"             android:textcolor="@color/cream_dark" />          <button             android:id="@+id/button4"             style="?android:attr/borderlessbuttonstyle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_marginend="4dp"             android:layout_marginright="4dp"             android:layout_margintop="4dp"             android:layout_weight="1"             android:background="@drawable/ic_launcher"             android:gravity="bottom|center_horizontal"             android:paddingbottom="18dp"             android:text="monuments"             android:textcolor="@color/cream_dark" />     </linearlayout>      <button         android:id="@+id/button7"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:text="expense calculator"         android:textcolor="@color/cream_dark" />  </linearlayout> 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -