1. Are you ready for the Galaxy S20? Here is everything we know so far!

Align the image and textview at center in Linear Layout.

Discussion in 'Android Development' started by Thayar, Jul 26, 2013.

  1. Thayar

    Thayar Newbie
    Thread Starter

    I have an Linear Layout with horizontal orientation
    Within that I have image on left side and textview on right side .
    How to align those image and textview in the center horizontal without using margin?

    Here is my code:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:eek:rientation="horizontal"
    android:background="@drawable/menu_colors"
    android:gravity="center_horizontal"
    >

    <ImageView
    android:id="@+id/menuimg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/film"
    android:layout_gravity="center_horizontal"
    />

    <TextView
    android:id="@+id/menutext"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:text="TextView"
    android:gravity="center_vertical"
    />

    </LinearLayout>
     


  2. out of ideas

    out of ideas Android Enthusiast

    Use relativelayouts

    and centerInParent="true" for the nested one.
     
    Thayar likes this.
Loading...

Share This Page

Loading...