Tuesday, July 19, 2016

android:gravity vs android:layout_gravity


This simple example show how android:gravity and android:layout_gravity affect the placement.


<?xml version="1.0" encoding="utf-8"?>
<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:padding="16dp"
    android:orientation="vertical"
    tools:context="com.blogspot.android_er.androidgravity.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:background="#D00000">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="200sp"
            android:layout_margin="10dp"
            android:gravity="center"
            android:layout_gravity="center"
            android:background="#0000C0"
            android:textSize="28sp"
            android:textStyle="bold"
            android:text="android-er"/>
    </LinearLayout>
</LinearLayout>


No comments:

Post a Comment