Reputation: 6936
I am learning android.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.raju.layoutlearn1.MainActivity"
android:background="#9cf"
android:orientation="horizontal">
<TextView
android:layout_width="160dp"
android:layout_height="160dp"
android:text="Hello World!"
android:layout_gravity="center_horizontal"
android:background="@color/colorAccent"/>
</LinearLayout>
I want the TextView
to be in the center horizontally. But it is not working.
How can I do that?
Upvotes: 0
Views: 101
Reputation: 7368
It's because your LinearLayout is horizontal. Make your LinearLayout orientation vertical.
Upvotes: 1