Reputation: 975
I have three edit text fields and I will hide second and third edit text in my to create () and I want to show first edit text in the center and if first edit text is valid then I will UN hide the second edit text and now I want to align first edit text and second edit text should be centered in layout.... so on vice versa
Upvotes: 0
Views: 59
Reputation: 740
try this layout `
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="first edit text"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second edit text"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second edit text"/>
</LinearLayout>
</RelativeLayout>`
and then hide the edit texts which you want to hide in the java code
Upvotes: 1
Reputation: 400
android:gravity="center"
Use this in the parent layout to center the elements
OR
You can use
android:layout_gravity="center"
in the element to center in its parent.
And for hiding the EditText, pls use
android:visibility="gone"
so that it doesn't take space in the layout
Upvotes: 2