eoweww eoweww - 2 months ago 16
Android Question

android programming auto margin as in css

I am very new to android programming.I have learned css and I want to make margin 0 auto like in css.This is my code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.qwe.androidtutorial_1.Layout">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="400dp"
android:orientation="vertical"
android:layout_marginLeft="0dp"
android:gravity="center_horizontal"
android:layout_gravity="center">


<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/alici"
android:visibility="visible"
android:gravity="center"
/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/konu"
android:visibility="visible"
android:gravity="center" />

</LinearLayout>

</RelativeLayout>


This is how my design looks like => IMAGE 1

I want to design like this =>IMAGE 2

I want to make this using margin 0 auto(as in css) which makes linearlayout perfectly vertically center in relativelayout.How can I make this?

Answer

set

android:gravity="center_horizontal"

in Main RelativeLayout.

Comments