Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 1  Your First Android Application


Do not worry about understanding what you are typing; you will learn how it works next. However, do
be careful. Layout XML is not validated, and typos will cause problems sooner or later.


You will see errors on the three lines that start with android:text. Ignore these errors for now; you
will fix them soon.


Listing 1.2  Defining widgets in XML (activity_quiz.xml)


<RelativeLayout
android:id="@+id/activity_quiz"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.bignerdranch.android.geoquiz.QuizActivity">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="@string/question_text" />


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/true_button" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/false_button" />



Free download pdf