Fuad
Fuad

Reputation: 1509

Could someone explain this bit of XML code please?

For android development, we need XML and I have a couple of doubts about the syntax.

Here's sample code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"

android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
<RelativeLayout android:id="@+id/vMain"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="false"
                    ads:adUnitId="@string/banner_ad_unit_id"
                    ads:adSize="BANNER"
                />
</RelativeLayout>

</RelativeLayout> 

On line 8, there is a >, could someone explain the significance of that? If I remove it, the editor complains because it seems to be invalid syntax.

Also, on line 12, if I replace the /> with the full closing tage of </RelativeLayout>, it will not work. Why?

Thanks!

Upvotes: 0

Views: 46

Answers (1)

Nick H
Nick H

Reputation: 8992

The '>' on line 8 closes the first <RelativeLayout node. '/>' is short hand for closing a node that has no children. The last </RelativeLayout> tag closes that first one. You can't replace it with '/>' because it has child nodes in it.

Upvotes: 1

Related Questions