My goal is to have a TextView
at the right of the Title, Stars and Thoughts.
I normally know how to do it with orientation="horizontal"
but actually this is quite tricky because I can't see what I am doing wrong.
Here's my code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:id="@+id/offertitle"
android:paddingTop="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/blue" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/troisieme"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:id="@+id/offerstars"
android:src="@drawable/stars" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:id="@+id/offerthoughts"
android:text="53 avis"
android:textColor="@color/blue" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/offer_price"
android:textColor="#000000"
android:gravity="right"
android:text="blablabla"
android:background="#D3D3D3"/>
Here is an image:
The Layout which contains title and etc. and is side by side with your TextView has width set as match_parent, it's wrong. there is no space for TextView then, below you have your design corrected. It has set width as 0dp and weight as 1 - so it fills available space.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/offertitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:textColor="@color/colorRed"
android:textSize="24dp"/>
<LinearLayout
android:id="@+id/troisieme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/offerstars"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:src="@drawable/ic_menu_start"/>
<TextView
android:id="@+id/offerthoughts"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="53 avis"
android:textColor="@color/colorOrange"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/offer_price"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#D3D3D3"
android:gravity="right"
android:text="blablabla"
android:textColor="#000000"/>
</LinearLayout>