Lesson 5
Lesson 5
TOPIC:
horizontally or vertically
◻RelativeLayout: Child object relative to each other
grid
Interfaces: Two Alternatives for
creation: Code or XML
◻ You have two ways you can create the interface(s)
of your Application.
1. Code = write code using SDK with classes like
LinearLayout, TextView, ……
<TextView
Here is code of
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Please Login"
layout created
android:id="@+id/textView_TopLabel" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="login"
android:id="@+id/textView_login" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText_Login" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="password"
android:id="@+id/textView_password" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText_Password" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button_Enter" />
</LinearLayout>
XML Interface tags
Besides drag and drop
you can edit the xml
file directly….you will
see examples
throughout this lecture
Lets return to looking at some of the
possible ViewGroup Layouts
Layout Options ---there are a
number
◻ Determines how the layout is structured.
■ LinearLayout
■ A Layout that arranges its children in a single column or a single row. The
direction of the row can be set by calling setOrientation()A Layout that arranges
its children in a single column or a single row. The direction of the row can be
set by calling setOrientation(). You can also specify gravity, which specifies the
alignment of all the child elements by calling setGravity() or specify that specific
children grow to fill up any remaining space in the layout by setting the weight
member of LinearLayout.LayoutParams. The default orientation is horizontal.
■ RelativeLayout
■ FrameLayout
■ GridLayout AND MANY MORE (see children of ViewGroup in API)
LinearLayout RelativeLayout GridLayout
LinearLayout
◻ Some Examples
LinearLayout
Good:
Simple
Know exactly how it will look on every device
Bad:
Well for many interfaces too simple….
BUT see next slide
BUT, REMEMBER you can have a ViewGroup
(another Layout) inside as a member of the
LinearLayout to make a more COMPLEX interface
ALSO can make more coplex
LinearLayout Very SIMPLE
Example
◻ arranges by single column (vertical orientation)
<Text View
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“@string/hello”/>
<Button android:id="@+id/btn_launchMyBrowser"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Launch My Browser"
android:onClick="onClickLaunchMyBrowser" />
Xml
android:orientation=“vertical”
Attribute Description