1 / 21

Tworzenie aplikacji mobilnych

Tworzenie aplikacji mobilnych. Android Kontenery. LinearLayout. android:layout_width android:layout_height 125dip wrap_content fill_parent ( match_parent wprowadzone w android 2.2). Orientacja. android:orientation HORIZONTAL VERTICAL setOrientation ().

meris
Download Presentation

Tworzenie aplikacji mobilnych

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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_weightIdentyfikuje 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="FiftyPercent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="50" /> <Button android:text="ThirtyPercent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="30" /> <Button android:text="TwentyPercent" 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" > <RadioGroupandroid: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> <RadioGroupandroid: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 ActivityimplementsRadioGroup.OnCheckedChangeListener { RadioGrouporientation; RadioGroupgravity; @Override public voidonCreate(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, intcheckedId) { switch(checkedId) { caseR.id.horizontal: orientation.setOrientation(LinearLayout.HORIZONTAL); break; caseR.id.vertical: orientation.setOrientation(LinearLayout.VERTICAL); break; caseR.id.left: gravity.setGravity(Gravity.LEFT); break; caseR.id.center: gravity.setGravity(Gravity.CENTER_HORIZONTAL); break; caseR.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_alignParentLeft: 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 widgetpionowo 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_toLeftOf: 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 prawejstroniewidgetu, 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 widgetbyć powinien wyrównany swoją dolną krawędzią z dolną krawędzią widgetu, na który wskazuje znacznik • android:layout_alignLeft: 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ówwzgleembaseline (linia przebiegu tekstu)

  14. Przykład • android:layout_toRightOf = "@id/widget_a" • @id/widget_a identyfikator widgetuA.

  15. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextViewandroid: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> <TextViewandroid: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:" /> <EditTextandroid: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"/> <TextViewandroid:text="#000000" android:paddingLeft="4dip" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80dip" android:background="#440000" /> <TextViewandroid:text="#440000" android:paddingLeft="4dip" android:layout_gravity="center_vertical" /> </TableRow> ….. </TableLayout> </ScrollView>

More Related