• Nie Znaleziono Wyników

Tworzenie aplikacji mobilnych

N/A
N/A
Protected

Academic year: 2021

Share "Tworzenie aplikacji mobilnych"

Copied!
21
0
0

Pełen tekst

(1)

Tworzenie aplikacji mobilnych

Android

Kontenery

(2)

LinearLayout

• android:layout_width

• android:layout_height

– 125dip

– wrap_content

– fill_parent (match_parent wprowadzone w

android 2.2)

(3)

Orientacja

• android:orientation

– HORIZONTAL – VERTICAL

• setOrientation()

(4)

• android:layout_weight

Identyfikuje proporcjonalną wartość wolnej

przestrzeni dla widgetu.

(5)

Gravity

• android:layout_gravity

– left,

– center_horizontal, – right

– center_vertical

(6)

Weight

• android:layout_marginTop

• android:layout_margin

(7)

<?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"

>

<Button

android:text="Fifty Percent"

android:layout_width="fill_parent"

android:layout_height="0dip"

android:layout_weight="50"

/>

<Button

android:text="Thirty Percent"

android:layout_width="fill_parent"

android:layout_height="0dip"

android:layout_weight="30"

/>

<Button

android:text="Twenty Percent"

android:layout_width="fill_parent"

android:layout_height="0dip"

android:layout_weight="20"

/>

</LinearLayout>

(8)

<?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"

>

<RadioGroup android:id="@+id/orientation"

android:orientation="horizontal"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="5dip">

<RadioButton

android:id="@+id/horizontal"

android:text="horizontal" />

<RadioButton

android:id="@+id/vertical"

android:text="vertical" />

</RadioGroup>

<RadioGroup android:id="@+id/gravity"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding="5dip">

<RadioButton android:id="@+id/left"

android:text="left" />

<RadioButton

android:id="@+id/center"

android:text="center" />

<RadioButton android:id="@+id/right"

android:text="right" />

</RadioGroup>

</LinearLayout>

(9)

import android.app.Activity;

import android.os.Bundle;

import android.view.Gravity;

import android.text.TextWatcher;

import android.widget.LinearLayout;

import android.widget.RadioGroup;

import android.widget.EditText;

public class LinearLayoutDemo extends Activity implements RadioGroup.OnCheckedChangeListener { RadioGroup orientation;

RadioGroup gravity;

@Override

public void onCreate(Bundle icicle) { super.onCreate(icicle);

setContentView(R.layout.main);

orientation=(RadioGroup)findViewById(R.id.orientation);

orientation.setOnCheckedChangeListener(this);

gravity=(RadioGroup)findViewById(R.id.gravity);

gravity.setOnCheckedChangeListener(this);

}

public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) {

case R.id.horizontal:

orientation.setOrientation(LinearLayout.HORIZONTAL);

break;

case R.id.vertical:

orientation.setOrientation(LinearLayout.VERTICAL);

break;

case R.id.left:

gravity.setGravity(Gravity.LEFT);

break;

case R.id.center:

gravity.setGravity(Gravity.CENTER_HORIZONTAL);

break;

case R.id.right:

gravity.setGravity(Gravity.RIGHT);

break;

} } }

(10)

RelativeLayout

(11)

Względne położenie widgetów w kontenerze

• android:layout_alignParentTop: Wyrównuje górną krawędź widgetu do górnej krawędzi kontenera

• android:layout_alignParentBottom: Wyrównuje dolną krawędź widgetu do dolnej krawędzi kontenera

• android:layout_alignParentLef: Wyrównuje lewą krawędź widgetu do lewej krawędzi kontenera

• android:layout_alignParentRight: Wyrównuje prawą krawędź widgetu do prawej krawędzi kontenera

• android:layout_centerHorizontal: Pozycjonuje widget poziomo w środku kontenera

• android:layout_centerVertical: Pozycjonuje widget pionowo w środku kontenera

• android:layout_centerInParent: Pozycjonuje widget jednocześnie poziomo i pionowo w środku kontenera

(12)

Położenie względem innego widgetu

• android:layout_above: Określa, że widget powinien być położony ponad widgetem, na który wskazuje znacznik

• android:layout_below: Określa, że widget powinien być położony pod widgetem, na który wskazuje znacznik

• android:layout_toLefOf: Określa, że widget powinien być położony po lewej stronie widgetu, na który

wskazuje znacznik

• android:layout_toRightOf: Określa, że widget powinien być położony po prawejstronie widgetu, na który

wskazuje znacznik

(13)

Wyrównanie widgetu względem innego

• android:layout_alignTop: Określa, że widget powinien być wyrównany swoją górną krawędzią z górną krawędzią widgetu, na który wskazuje znacznik

• android:layout_alignBottom: Określa, że widget być powinien wyrównany swoją dolną krawędzią z dolną krawędzią widgetu, na który wskazuje

znacznik

• android:layout_alignLef: Określa, że widget być powinien wyrównany swoją lewą krawędzią z lewą krawędzią widgetu, na który wskazuje znacznik

• android:layout_alignRight: Określa, że widget być powinien wyrównany swoją prawą krawędzią z prawą krawędzią widgetu, na który wskazuje znacznik

• android:layout_alignBaseline: Określa wyrównanie dwóch widgetów wzgleem baseline (linia przebiegu tekstu)

(14)

Przykład

• android:layout_toRightOf = "@id/widget_a"

• @id/widget_a identyfikator widgetu A.

(15)

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content">

<TextView android:id="@+id/label"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="URL:"

android:layout_alignBaseline="@+id/entry"

android:layout_alignParentLeft="true"/>

<EditText

android:id="@id/entry"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/label"

android:layout_alignParentTop="true"/>

<Button

android:id="@+id/ok"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/entry"

android:layout_alignRight="@id/entry"

android:text="OK" />

<Button

android:id="@+id/cancel"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toLeftOf="@id/ok"

android:layout_alignTop="@id/ok"

android:text="Cancel" />

</RelativeLayout>

(16)

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<Button

android:text="I AM BIG"

android:textSize="120dip"

android:textStyle="bold"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

/>

<Button

android:text="I am small"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

/>

</RelativeLayout>

(17)

TableLayout

<TableRow>

<TextView android:text="URL:" />

<EditText

android:id="@+id/entry"

android:layout_span="3"/>

</TableRow>

(18)

Kolumny

<TableRow>

<Button

android:id="@+id/cancel"

android:layout_column="2"

android:text="Cancel" />

<Button android:id="@+id/ok"

android:text="OK" />

</TableRow>

(19)

• android:stretchColumns

• android:shrinkColumns

• android:collapseColumns

• setColumnCollapsed()

• setColumnShrinkable()

(20)

<?xml version="1.0" encoding="utf-8"?>

<TableLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="1">

<TableRow>

<TextView

android:text="URL:" />

<EditText android:id="@+id/entry"

android:layout_span="3"/>

</TableRow>

<View

android:layout_height="2dip"

android:background="#0000FF" />

<TableRow>

<Button android:id="@+id/cancel"

android:layout_column="2"

android:text="Cancel" />

<Button android:id="@+id/ok"

android:text="OK" />

</TableRow>

</TableLayout>

(21)

ScrollView

<?xml version="1.0" encoding="utf-8"?>

<ScrollView

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content">

<TableLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="0">

<TableRow>

<View

android:layout_height="80dip"

android:background="#000000"/>

<TextView android:text="#000000"

android:paddingLeft="4dip"

android:layout_gravity="center_vertical" />

</TableRow>

<TableRow>

<View

android:layout_height="80dip"

android:background="#440000" />

<TextView android:text="#440000"

android:paddingLeft="4dip"

android:layout_gravity="center_vertical" />

</TableRow>

…..

</TableLayout>

</ScrollView>

Cytaty

Powiązane dokumenty

 Zdobycie praktycznych umiejętności programowania aplikacji mobilnych działających pod kontrolą najpopularniejszego systemu operacyjnego dedykowanego do urządzeń

Fragment poni- żej ujścia prawej żyły podobojczykowej to żyła ra- mienno-głowowa prawa, a poniżej ujścia żyły ra- mienno-głowowej lewej — żyła górna główna [2].. W

c) wyłączenie z zalesień siedlisk występowania chronionych gatunków grzybów, roślin i zwierząt, a w miarę możliwości także łąk zmiennowilgotnych, łąk wilgotnych i

Siedziałam w półmroku i patrzyłam przez oszkloną ścianę na przesuwające się po torach pociągi, zrzędziły przy hamowaniu marudnie.. Słuchałam wwiercającego

• getRootView(): Znajduje główny kontener całego activity ustawiony

• Odpowiadają zarówno za dostęp do danych ja i za konwersje do odpowiednich

CHARAKTERYSTYKA FLORY I ZAGADNIENIE JEJ WIEKU Diagram pyłkowy or.az 'lista roślin oznaczonych na podstawie szczątków.. makroskopowych dowodzi, ż'e w całym okresie

Ze względu na solidne wykończenie, wysoką wytrzymałość mechaniczną, odporność chemiczną oraz dzięki zintegrowa- nym żeliwnym profilom zabezpieczającym, korytka STORA SUPER