1. Download our Official Android App: Forums for Android!

Apps 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
    Rank:
    None
    Points:
    35
    Posts:
    17
    Joined:
    Jul 15, 2013

    Jul 15, 2013
    17
    0
    35
    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>
     

    Advertisement

  2. out of ideas

    out of ideas Android Enthusiast
    Rank:
    None
    Points:
    93
    Posts:
    640
    Joined:
    May 19, 2012

    May 19, 2012
    640
    145
    93
    Use relativelayouts

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

Share This Page

Loading...