Align Imageview & Textview Inside Linearlayout
I have a LinearLayout and inside, a ImageView and TextView. I want to align the center of the LinearLayout the ImageView and the TextView below the ImageView. I only get the top a
Solution 1:
I'll show you how to do the same taking advantage of a RelativeLayout and a TextView's compoundDrawable:
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center_horizontal"android:layout_margin="8dp"
><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:drawableTop="@drawable/plano"android:drawablePadding="8dp"android:text="Plano"android:textSize="23sp"android:textStyle="bold"
/></RelativeLayout>
Compound drawables help keeping down the View count, and therefore intrinsically speed up the layout
The key is android:drawableTop="@drawable/plano"
This replaces the top image.
You can also set a Right, Left, Bottom side image.
Even all together.
Solution 2:
You have to put the "layout_gravity" field as "center_horizontal" but the two widgets (ImageView, TextView).
Here code:
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/imageView"android:layout_gravity="center_horizontal"android:src="@drawable/ic_launcher"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textAppearance="?android:attr/textAppearanceSmall"android:text="Small Text"android:id="@+id/textView"android:layout_gravity="center_horizontal"/></LinearLayout>
Post a Comment for "Align Imageview & Textview Inside Linearlayout"