Place a image view and a Text view in same line

16,616

Method 1:

Like others have suggested, you can have a nested LinearLayoutwith horizontal orientation. It will contain both TextView and ImageView with weights set according to your need.

See How to set ImageView and the textView in a single line inside a LinearLayout

Eg:

 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal" >

     <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="0.5"
         ...
         />

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dp"
         android:layout_weight="0.5"
         android:text="Test2" />
</LinearLayout>

Method 2 [ Easier ]:

Since you mentioned that you've several logos and want to set the drawable/ImageView right next to it, there is an easier alternate way. Supposing you want something like this: enter image description here

You can use android:drawableLeft or similar in the TextView. You can also set the padding between the drawable and the text of the TextView using android:drawablePadding. Using this way you don't need the extra ImageView. But it depends at the end what you are looking for.

See Programmatically set left drawable in a TextView

Hope this helps.

Share:
16,616
CraZyDroiD
Author by

CraZyDroiD

Updated on June 04, 2022

Comments

  • CraZyDroiD
    CraZyDroiD almost 2 years

    I have several logos and i want to set a Textview right next to it so that they are in the same line. I can't place them in the same line.please help me. I want my textview right next to my image.

    my layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <!--
          <fragment 
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
        -->
    
        <TextView
            android:id="@+id/filmhall_contactdetails"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cinema_filmhall_contactdet"
            android:textColor="#000000"
            android:layout_margin="4dp"
            android:toRightof="@+id/pointer"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/filmhall_address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="2dp"
            android:text="@string/cinema_filmhall_address"
            android:textColor="#000000"
            android:textSize="12sp"
            android:textStyle="bold" />
    
        <ImageView
            android:id="@+id/pointer"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_marginLeft="4dp"
    
            android:src="@drawable/pointer" />
    
        <TextView
            android:id="@+id/filmhall_telephone1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cinema_filmhall_tp1"
            android:textColor="#000000"
             android:layout_marginTop="2dp"
             android:layout_marginLeft="32dp"
              android:textSize="12sp"
            android:textStyle="bold" />
    
        <ImageView
            android:id="@+id/telephone"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_marginLeft="4dp"
            android:src="@drawable/call" />
    
        <TextView
            android:id="@+id/filmhall_telephone2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cinema_filmhall_tp2"
            android:textColor="#000000"
             android:layout_marginTop="2dp"
             android:layout_marginLeft="32dp"
              android:textSize="12sp"
            android:textStyle="bold" />
    
        <ImageView
            android:id="@+id/fax"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_marginLeft="4dp"
            android:src="@drawable/fax" />
    
        <TextView
            android:id="@+id/filmhall_email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cinema_filmhall_email"
            android:textColor="#000000"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="32dp"
             android:textSize="12sp"
            android:textStyle="bold" />
    
        <ImageView
            android:id="@+id/message"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_marginLeft="4dp"
            android:src="@drawable/message" />
    
        <TextView
            android:id="@+id/filmhall_facility"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:layout_marginTop="10dp"
            android:text="@string/cinema_filmhall_facility"
            android:textColor="#000000"
            android:textStyle="bold" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
    >
    
    
            <ImageView
                android:id="@+id/fac1"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginLeft="4dp"
                android:src="@drawable/fac1" />
    
            <ImageView
                android:id="@+id/fac3"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginLeft="4dp"
                android:src="@drawable/fac3" />
    
            <ImageView
                android:id="@+id/fac2"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginLeft="4dp"
                android:src="@drawable/fac2" />
        </LinearLayout>
    
    </LinearLayout>