Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android linear layout place two items next to each other

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?

like image 835
Zapnologica Avatar asked Mar 17 '14 10:03

Zapnologica


People also ask

Is linear layout deprecated?

This constant is a layoutMode . This constant is a layoutMode . This constant was deprecated in API level 28.

Is constraint layout better than linear layout?

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.

How do you use nested linear layout?

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.

Which layout allows us to display items on the screen relative to each other?

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).


1 Answers

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.

like image 94
Renjith Krishnan Avatar answered Oct 13 '22 12:10

Renjith Krishnan