I would like to add multiple buttons with textviews left to right in the same row and normally would set the orientation to horizontal for this but I need the vertical in order to place the textview "cash app" under the image where I need it how can I accomplish this? I heard something about container layouts but not sure how to do this, any help would be appreciated.
First of all you can wrap your "button" in another XML layout like, let's name it custom_view_button.xml
.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageViewCashApp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cashapp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cash app"
/>
</LinearLayout>
And then in your activity_layout.xml, include it like below. Take note of the weightSum
and layout_weight
values in order for equal widths.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<include
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
layout="@layout/custom_view_button"
/>
<include
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
layout="@layout/custom_view_button"
/>
</LinearLayout>