Friday, 30 January 2015

What is the importance about sequence of declaring elements in xml



I am just learning Android programming so I decided to write a simple app about calculating BMI of people! the problem I have is that when I declare my TextView and Button first and then ImageView, all three elements fit in the screen both in portrait and landscape mode:



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context="com.example.bmicalculator.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BMI Calculator" />
<Button
android:id="@+id/button1"
android:layout_width="195dp"
android:layout_height="33dp"
android:text="Start"
android:textSize="15dp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/splash" />



But when I change the sequence and declare TextView and Button after ImageView output changes in landscape mode, TextView vanishes! Only half of Button shows and image overlays with top setting bar:



But still portrait mode is OK



So what changes when I change sequence of declaring these elements in xml? and how can I solve this. thnx


No comments:

Post a Comment