I want to draw two Buttons in one line with equal width. Say, they have captions: "Sample text" and "Extra text". They should occupy as low space as possible, but all words should be written.
I wrote this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:maxLines="1"
android:text="Sample text"
android:textAllCaps="false" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:maxLines="1"
android:text="Extra text"
android:textAllCaps="false" />
</LinearLayout>
If I remove android:maxLines="1" and set wrap_content to width, Buttons write a text, but fill different widths.

Let you want to resize second button.
If a button contains an icon, center it with How to center icon and text in a android button with width set to "fill parent". For instance, move a
Buttoninside aFrameLayoutor create aLinearLayoutwithImageViewandTextView.If your case is custom view and a button is a
FrameLayoutwith icon, override the following event:If you have a button without an icon, only text, a resizing will be simplier: