Android Dev Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Notes

XML syntax

Here the linear layout view has a opening tag but no closing tag.

It is closed later in the code using a forward slash

Also, we have two xml elements in the linear layout view known as children xml with parent as linear
layout view.

The reason being It is not closed at the time when it was opened is we could not know the no of
children it is having.

Here src is the location of the source from where you want to display the image

Scale type means at what position you want it to get displayed


The two types of linear layout are:-
Relative layout:- A RelativeLayout is a common type of ViewGroup that lets us position its children
relative to its own edges. For example, the three children in the illustration are placed in the corners
of a Relative Layout. A Relative Layout also lets us arrange its children relative to each other: one
child can be placed to the right of another, and can even overlap.{more information on next page }

Example:-
Some child view attributes relative to the parent (placing view relative to the parent)

Four attributes will help you to place child view any desiered position
Padding and margin:-
padding

margin
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:contentDescription="@string/image_1"
app:srcCompat="@drawable/androidparty"
/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Happy_birthday"
android:padding="20dp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/white"
android:textSize="32sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/from_devansh"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/white"
android:textSize="32sp"
android:padding="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"

/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
App developed using the above code.

You might also like