Reputation: 2518
I'm trying to have a layout with 3 images that has space between them, but i have a textview below every image and i would like the textview to be 20dp larger in width from the images.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:weightSum="6"
android:orientation="horizontal">
<Space
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="@dimen/abc_action_bar_content_inset_with_nav"
android:paddingRight="@dimen/abc_action_bar_content_inset_with_nav"
android:orientation="vertical">
<ImageButton
android:src="@drawable/ic_sad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SadImageButton"
android:background="@null"
android:scaleType="fitCenter" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/SadTextTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:visibility="gone"
app:autoSizeTextType="uniform"
android:minLines="4"
android:maxLines="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:src="@drawable/ic_neutral"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/NeutralImageButton"
android:background="@null"
android:scaleType="fitCenter" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/NeutralTextTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:visibility="gone"
android:minLines ="4"
android:maxLines ="4"
app:autoSizeTextType="uniform"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:src="@drawable/ic_happy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/HappyImageButton"
android:background="@null"
android:scaleType="fitCenter" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/HappyTextTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:visibility="gone"
android:maxLines ="4"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<Space
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
I have try adding padding to the layout that holds the image with the textview or to the textview but i can't manage to do what i want, any ideas?
This is the look of the iamges without text and this is what im getting without the constraint layout If i use constraint layout the width of the test is equal to the image, i want it to be larger.
Upvotes: 1
Views: 995
Reputation: 3659
I suppose you want to get something like this:
And here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="2"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:src="@drawable/icon_red"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:text="@string/lorem_ipsum"
/>
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:src="@drawable/icon_green"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:text="@string/lorem_ipsum"
/>
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:src="@drawable/icon_blue"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:text="@string/lorem_ipsum"
/>
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="2"/>
</LinearLayout>
</FrameLayout>
Upvotes: 1