I have the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status:"
android:layout_gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/txcpluss_imageView_refresh"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:clickable="true"
android:contentDescription="icon"
android:gravity="right"
android:src="@drawable/refresh_big" />
</LinearLayout>
</LinearLayout>
But my refresh icon is not in the top right hand corner where I want it. It sits right next to the text view.
How can I get the text view to be on the left and the refresh icon on the right with white space between them?
This constant is a layoutMode . This constant is a layoutMode . This constant was deprecated in API level 28.
ConstraintLayout has dual power of both Relative Layout as well as Linear layout: Set relative positions of views ( like Relative layout ) and also set weights for dynamic UI (which was only possible in Linear Layout). Despite the fact that it's awesome, it fails to serve the purpose with simple UI layouts.
Show activity on this post. add this tag to all your list views, so this will maintain symmetry in all your textView placement. Secondly: Keep a single Parent LinearLayout with orientation vertical, then have multiple LinearLayout with horizontal orientation and two TextView inside it.
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
Use the Following code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:text="Status:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/txcpluss_imageView_refresh"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:clickable="true"
android:contentDescription="icon"
android:gravity="right"
android:src="@drawable/refresh_big" />
</LinearLayout>
I added weight for the text view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With