Ticker

6/recent/ticker-posts

Change UI elements by changing main.xml

In the previous article, "Exercise: Hello World with EditText input", all the elements are placed in a single LinearLayout, both the OK and Cancel button's width are defined as wrap_content. It can be noted that the layout is not good aligned.

The layout can be changed by changing main.xml, without any modification on the java code.


android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Who you are?"
/>
android:id = "@+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:id = "@+id/ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="OK" />
android:id = "@+id/cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel" />







android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Who you are?"
/>
android:id = "@+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id = "@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />
android:id = "@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />









android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Who you are?"
/>
android:id = "@+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right|bottom"
>
android:id = "@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />
android:id = "@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />





Download the project files

إرسال تعليق

0 تعليقات