How can I place two buttons next to the image at the bottom of the button?

How to place two buttons next to the image at the bottom of the button?

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/a_button" android:layout_width="wrap_content" android:layout_height="35dp" android:text="Button-a" /> <Button android:id="@+id/b_button" android:layout_width="wrap_content" android:layout_height="35dp" android:text="Button-b" /> </LinearLayout> 
+4
source share
3 answers

Instead of using the u button, you can use the Clickable line layout and use your id instead of Button id.something like this ...... Using this, you can customize your button according to your requirements.

 <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" > 

// Button-A

  <LinearLayout android:id="@+id/a_button" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.50" android:orientation="vertical" android:clickable="true"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal|center_vertical" android:text="Text-A" android:paddingTop="10dip" /> <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="fitXY" android:src="@drawable/image_A" android:paddingTop="13dip" /> </LinearLayout> 

// For the horizontal section line

  <TextView android:layout_width="2dp" android:layout_height="fill_parent" android:background="#303030" android:paddingTop="20dip" /> 

// Button-B

  <LinearLayout android:id="@+id/b_button" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="0.50" android:orientation="vertical" android:clickable="true"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Text-B" android:gravity="center_horizontal|center_vertical" android:paddingTop="10dip" /> <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="fitXY" android:src="@drawable/image_B" android:paddingTop="13dip" /> </LinearLayout> </LinearLayout> 
+1
source

Just add the bottom line to your buttons and specify the appropriate option that you want to use.

 android:drawableBottom="@drawable/image" 

Hope this helps.

EDIT: The above method works if you want to use your drawings, as it is, without resizing it. If you want you to change your capabilities, you can also do this with simple Java code written below:

 ((Button)findViewById(R.id.button)).setCompoundDrawables(null, null, null, getDrawable(getApplicationContext(), R.drawable.image, 25)); 

..... .....

 Drawable getDrawable(Context context, int drawable, float form_factor) { Drawable imgDrawable = context.getResources().getDrawable(drawable); imgDrawable.setBounds(0, 0, (int)form_factor, (int)form_factor); return imgDrawable; } 
+1
source

Images can be placed at the bottom of buttons using the Drawable_Bottom property.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" style="@android:attr/buttonBarStyle" android:orientation="horizontal" > <Button android:id="@+id/a_button" style="@android:attr/buttonBarButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableBottom="@android:drawable/btn_star" android:text="Button-a" /> <Button android:id="@+id/b_button" style="@android:attr/buttonBarButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableBottom="@android:drawable/btn_star" android:text="Button-b" /> </LinearLayout> 
+1
source

Source: https://habr.com/ru/post/1480880/


All Articles