/*public void initComponent()
{
lblHeader = (TextView)findViewById(R.id.lblHeaderCity);
lvCity = (ListView)findViewById(R.id.lvCity);
arrListCity = getResources().getStringArray(R.array.list_city_central);
lblHeader.setText(R.string.central);
ListViewAdapter adapter = new ListViewAdapter(this, arrListCity);
lvCity.setAdapter(adapter);
}*/
Showing posts with label AbsoluteLayout. Show all posts
Showing posts with label AbsoluteLayout. Show all posts
Thursday, October 13, 2011
Monday, October 3, 2011
TextView font size color layout interface andoid exam
I created a new Android Project in Eclipse called “AndroidFonts”:

From here I modified the “main.xml” file in the layout folder.
When I run the project I get this result in the emulator:

As you can see from the code I used the fonts: sans, serif, and monospace. Then I showed off how to make a string bold and italic:
Then a string utilizing the shadowing effect:
Colors are as simple as adding:
Pretty easy!
From here I modified the “main.xml” file in the layout folder.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="MonoSpace Font:" android:textSize="16sp" android:paddingLeft="5sp" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5sp" android:typeface="monospace" android:text="Hello Red Monospace" android:textSize="16sp" android:textColor="#ff0000" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Sans Font:" android:textSize="16sp" android:paddingLeft="5sp" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5sp" android:typeface="sans" android:text="Hello Blue Sans" android:textSize="16sp" android:textColor="#0000ff" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Serif Font:" android:textSize="16sp" android:paddingLeft="5sp" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5sp" android:paddingRight="2sp" android:typeface="serif" android:text="Hello Green Serif" android:textSize="16sp" android:textColor="#00ff00" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5sp" android:paddingTop="15sp" android:typeface="normal" android:text="I'm normal font but I'm also bold and italic" android:textSize="16sp" android:textStyle="bold|italic" android:textColor="#ffffff" /> <TextView android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5sp" android:paddingTop="15sp" android:paddingBottom="15sp" android:typeface="normal" android:text="I'm normal (bold) font but I have a shadow" android:textSize="16sp" android:textStyle="bold" android:shadowColor ="#0f0f0f" android:shadowRadius="1.6" android:shadowDx="1.5" android:shadowDy="1.3" android:textColor="#000000" android:background="#ffffff" /></LinearLayout> |
As you can see from the code I used the fonts: sans, serif, and monospace. Then I showed off how to make a string bold and italic:
android:textStyle="bold|italic" |
android:shadowColor ="#0f0f0f"android:shadowRadius="1.6"android:shadowDx="1.5"android:shadowDy="1.3" |
android:textColor="#ff0000" |
Friday, September 30, 2011
ScrollView android exam
ScrollView
AScrollView is a special type of FrameLayout in that it allows users to scroll through a list of views that occupy more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout. Note: Do not use a
ListView together with the ScrollView. The ListView is designed for showing a list of related information and is optimized for dealing with large lists. The following
main.xml content shows a ScrollView containing a LinearLayout, which in turn contains some Button and EditText views:<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/widget54" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:layout_width="310px" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 3" /> <EditText android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="300px" /> <Button android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 4" /> <Button android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 5" /> </LinearLayout> </ScrollView>
ScrollView displaying a scroll bar on the right side of the screen. Users can drag the screen upward to reveal the views located at the bottom of the screen. Figure 12 Using the ScrollView
Labels:
AbsoluteLayout,
FrameLayout,
LinearLayout,
RelativeLayout,
ScrollView,
TableLayout
FrameLayout android exam
FrameLayout
TheFrameLayout is a placeholder on screen that you can use to display a single view. Views that you add to a FrameLayout is always anchored to the top left of the layout. Consider the following content in main.xml:<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget68" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="40px" android:layout_y="35px" > <ImageView android:src = "@drawable/androidlogo" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </FrameLayout> </AbsoluteLayout>
FrameLayout within an AbsoluteLayout. Within the FrameLayout, you embed an ImageView view. The UI is as shown in Figure 10. Note: This example assumes that the
res/drawable folder has an image named androidlogo.png. Figure 10 Using FrameLayout
FrameLayout, the view will overlap the previous view (see also Figure 11):<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget68" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="40px" android:layout_y="35px" > <ImageView android:src = "@drawable/androidlogo" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:layout_width="124px" android:layout_height="wrap_content" android:text="Print Picture" /> </FrameLayout> </AbsoluteLayout>
Figure 11 Overlapping views
FrameLayout, but each will stack on top of the previous one.
Labels:
AbsoluteLayout,
FrameLayout,
LinearLayout,
RelativeLayout,
ScrollView,
TableLayout
RelativeLayout android exam
RelativeLayout
The RelativeLayout lets you specify how child views are positioned relative to each other. Consider the followingmain.xml file:<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:id="@+id/lblComments" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Comments" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" /> <EditText android:id="@+id/txtComments" android:layout_width="fill_parent" android:layout_height="170px" android:textSize="18sp" android:layout_alignLeft="@+id/lblComments" android:layout_below="@+id/lblComments" android:layout_centerHorizontal="true" /> <Button android:id="@+id/btnSave" android:layout_width="125px" android:layout_height="wrap_content" android:text="Save" android:layout_below="@+id/txtComments" android:layout_alignRight="@+id/txtComments" /> <Button android:id="@+id/btnCancel" android:layout_width="124px" android:layout_height="wrap_content" android:text="Cancel" android:layout_below="@+id/txtComments" android:layout_alignLeft="@+id/txtComments" /> </RelativeLayout>
RelativeLayout have attributes that allow them to align with another view. These attributes are:layout_alignParentToplayout_alignParentLeftlayout_alignLeftlayout_alignRightlayout_belowlayout_centerHorizontal
Figure 9 Using RelativeLayout to layout views
Labels:
AbsoluteLayout,
FrameLayout,
LinearLayout,
RelativeLayout,
ScrollView,
TableLayout
TableLayout android exam
TableLayout
TheTableLayout groups views into rows and columns. You use the <TableRow> element to designate a row in the table. Each row can contain one or more views. Each view you place within a row forms a cell. The width for each column is determined by the largest width of each cell in that column.Populate
main.xml with the following elements and observe the UI as shown in Figure 7. <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="#000044"> <TableRow> <TextView android:text="User Name:" android:width ="120px" /> <EditText android:id="@+id/txtUserName" android:width="200px" /> </TableRow> <TableRow> <TextView android:text="Password:" /> <EditText android:id="@+id/txtPassword" android:password="true" /> </TableRow> <TableRow> <TextView /> <CheckBox android:id="@+id/chkRememberPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Remember Password" /> </TableRow> <TableRow> <Button android:id="@+id/buttonSignIn" android:text="Log In" /> </TableRow> </TableLayout>
Figure 7 Using the TableLayout
Figure 8 Note the change in the position of the Remember Password view
Labels:
AbsoluteLayout,
FrameLayout,
LinearLayout,
RelativeLayout,
ScrollView,
TableLayout
AbsoluteLayout android exam
AbsoluteLayout
The AbsoluteLayout lets you specify the exact location of its children. Consider the following UI defined inmain.xml:<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <Button android:layout_width="188px" android:layout_height="wrap_content" android:text="Button" android:layout_x="126px" android:layout_y="361px" /> <Button android:layout_width="113px" android:layout_height="wrap_content" android:text="Button" android:layout_x="12px" android:layout_y="361px" /> </AbsoluteLayout>
Button views located at their specified positions using the android_layout_x and android_layout_y attributes. Figure 6 Views laid out using AbsoluteLayout
AbsoluteLayout when you need to reposition your views when there is a change in the screen rotation.
Labels:
AbsoluteLayout,
FrameLayout,
LinearLayout,
RelativeLayout,
ScrollView,
TableLayout
LinearLayout android exam
LinearLayout
TheLinearLayout arranges views in a single column or single row. Child views can either be arranged vertically or horizontally. To see how LinearLayout works, let's modify the main.xml file in the project:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
main.xml file, observe that the root element is <LinearLayout> and it has a <TextView> element contained within it. The <LinearLayout> element controls the order in which the views contained within it appear. Each View and
ViewGroup has a set of common attributes, some of which are shown in Table 1.| Attribute | Description |
|---|---|
layout_width | Specifies the width of the View or ViewGroup |
layout_height | Specifies the height of the View or ViewGroup |
layout_marginTop | Specifies extra space on the top side of the View or ViewGroup |
layout_marginBottom | Specifies extra space on the bottom side of the View or ViewGroup |
layout_marginLeft | Specifies extra space on the left side of the View or ViewGroup |
layout_marginRight | Specifies extra space on the right side of the View or ViewGroup |
layout_gravity | Specifies how child Views are positioned |
layout_weight | Specifies how much of the extra space in the layout to be allocated to the View |
layout_x | Specifies the x-coordinate of the View or ViewGroup |
layout_y | Specifies the y-coordinate of the View or ViewGroup |
Table 1 Common attributes of views and viewgroups
Note that some of these attributes are only applicable when a View is in certain specific ViewGroup(s). For example, the layout_weight and layout_gravity attributes are only applicable if a View is either in a LinearLayout or TableLayout.For example, the
<TextView> element above has its width filling up the entire width of its parent (which is the screen in this case) using the fill_parent constant. Its height is indicated by the wrap_content constant, which means that its height is the height of its content (in this case, the text contained within it). If you do not wish to have the <TextView> view occupy the entire row, you can set its layout_width attribute to wrap_content, like this:<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" />
<TextView android:layout_width="105px" android:layout_height="wrap_content" android:text="@string/hello" />
main.xml file by adding a <Button> view as shown below:<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:layout_width="105px" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:layout_width="100px" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout>
Labels:
AbsoluteLayout,
FrameLayout,
LinearLayout,
RelativeLayout,
ScrollView,
TableLayout
Subscribe to:
Posts (Atom)