I have a requirement where there needs to be a horizontal row of buttons with different images for different tap states and text on the bottom. For the life of me, I can't figure out how to keep the aspect ratio, my button backgrounds look stretched wide.
I'm using a LinearLayout
and each button
has equal weight. That made the buttons
equal size to each other but I wanted to keep the background image aspect ratio square. The ideal layout would be a row of square sized buttons...
I have tried this solution but it is for an ImageButton
.
My main.xml looks like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:weightSum="5">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/menu"
android:gravity="center|bottom"
android:text="Settings" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@null" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@null" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@null" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@null" />
</LinearLayout>
And my layout looks like this, yes I realize some buttons don't have images yet. How should I fix the aspect ratio?