Showing posts with label RelativeLayout. Show all posts
Showing posts with label RelativeLayout. Show all posts

How to Align an ImageView to the Right in a View

android:layout_alignParentRight was added in API Level 1
If true, makes the right edge of this view match the right edge of the parent. Accommodates right margin.
Must be a boolean value, either "true" or "false".

1. In your main.xml file, add a RelativeLayout.

2. Add an ImageView  to the main.xml file.

3. Add the below line between the <ImageView> tags. This will move the ImageView to the Right of the view within its parent.

android:layout_alignParentRight = "true"

4. Compile and run!

Next Recommended Article: android:gravity - Move Text inside a EditText (center, top, bottom, right, left, and more)

Resources:
developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_alignParentRight

How to Align an EditText to the Bottom in a View

android:layout_alignBottom was added in API Level 1
Makes the bottom edge of this view match the bottom edge of the given anchor view ID. Accommodates bottom margin.

1. In your main.xml file, add a RelativeLayout.

2. Add an EditText to the main.xml file.

3. Add the below line between the <EditText> tags. This will move the EditText to the bottom of the view within its parent.

android:layout_alignParentBottom = "true"

4. Compile and run!

Next Recommended Article: android:gravity - Move Text inside a EditText (center, top, bottom, right, left, and more)

Resources:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_alignBottom

How to Center a TextView within a RelativeLayout

android:layout_centerInParent
This only works in Relativelayout View. It does not work in LinearLayout.
If true, centers this child horizontally and vertically within its parent.

1. In your main.xml file, add a RelativeLayout.

2. Add a TextView to the main.xml file.

3. Add the below line between the <TextView> tags. This will center the TextView horizontally and vertically within its parent.

android:layout_centerInParent="true"

4. Compile and run!

Next Recommended Article: android:gravity - Move Text inside a EditText (center, top, bottom, right, left, and more)

Resources:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_centerInParent

RelativeLayout

RelativeLayout is a layout where the positions of the children can be described in relation to each other or to the parent.

1. Ensure to change the minSDKVersion to 8, or greater if using match_parent. If using the deprecated, fill_parent, any API level will work.

2. In your main.xml file, add the following code for a RelativeLayout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</RelativeLayout>

3. Compile and run!

Resources:
http://developer.android.com/reference/android/widget/RelativeLayout.html