Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3 Zablon Ochomo zochomo@icontrace.com Android Layouts Lecture 3 Zablon Ochomo zochomo@icontrace.com.

Similar presentations


Presentation on theme: "Lecture 3 Zablon Ochomo zochomo@icontrace.com Android Layouts Lecture 3 Zablon Ochomo zochomo@icontrace.com."— Presentation transcript:

1 Lecture 3 Zablon Ochomo zochomo@icontrace.com
Android Layouts Lecture 3 Zablon Ochomo

2 Android Layouts Android layout is the architecture for the user interface in an Activity. It defines the layout structure and holds all the elements that appear to the user. You can declare your layout in two ways: Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. Instantiate layout elements at runtime. Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

3 Android Layout The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile. For example, you can create XML layouts for different screen orientations, different device screen sizes, and different languages. Additionally, declaring the layout in XML makes it easier to visualize the structure of your UI, so it's easier to debug problems

4 #Class Exercise# Create an android app that has main screen with two buttons: call and sms. When call button is clicked, it takes you to a screen with phone number label, phone number input and dial button. When sms button is clicked, it takes you to a screen with phone number label, phone input text, message label, message input text and send button.

5 Exercise guidelines Create the three layouts XML files: phone.xml, call_layout.xml and text.xml You can use your own names as long as they are legal android layout names. phone.xml is for the main screen, call_layout.xml is for call screen and text.xml is for SMS screen.

6 phone.xml <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Call"/> <Button android:text="Text"/> </LinearLayout>

7 call_layout.xml <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" res/android" android:text="Message: " android:orientation="vertical" android:layout_width="fill_parent" <EditText android:layout_height="fill_parent" > <TextView android:layout_height="wrap_content" android:text="Phone Number: " /> <EditText <Button android:layout_width="wrap_content" android:text="" android:text="Send"/> android:editable="true" </LinearLayout> android:textColor="#ff0000"

8 text.xml <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_height="wrap_content" android:text="Phone Number: " /> <EditText android:text="" android:editable="true" android:textColor="#ff0000" <Button android:layout_width="wrap_content" android:text="Dial"/> </LinearLayout>

9 Manifest file .. So far! <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=" package="cisy.lab2" android:versionCode="1" android:versionName="1.0"> <application > <activity android:name="Lab2Activity" <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

10 Lab2Activity.java package cisy.lab2; import android.app.Activity;
import android.os.Bundle; public class Lab2Activity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.text); } ### change line 11 with other layouts to test them

11


Download ppt "Lecture 3 Zablon Ochomo zochomo@icontrace.com Android Layouts Lecture 3 Zablon Ochomo zochomo@icontrace.com."

Similar presentations


Ads by Google