.


:




:

































 

 

 

 


Layouts




. 1 . XML-, . , TextView.

, .

-, Palette ( ) Properties ( ) (.2.2).

- . Android , XML-. XML- res/layout . "res" "resources" (). , . , , .. res/layout, activity_main.xml ( ) . XML- : . Palette: Design Text. Text XML:

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"

android:id="@+id/hello_world">

<TextView android:text="@string/hello_world" android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="44dp"

android:id="@+id/textView" />

</RelativeLayout>

Design (Delete), Text - activity_main.xml.

c Layouts, . Design Palette. Layouts, View.

1. FrameLayout (, , ) . FrameLayout . , View ViewGroup. FrameLayout .

FrameLayout View. , View , , , FrameLayout .

Layouts FrameLayout, . , XML- (activity_main.xml) , , :

<FrameLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_centerVertical="true"

android:layout_alignRight="@+id/textView"

android:layout_alignEnd="@+id/textView"

android:layout_marginRight="23dp"

android:layout_marginEnd="23dp"></FrameLayout>

, ( 2 ), , , .

( Design) :

<FrameLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_below="@+id/textView"

android:layout_marginTop="23dp"></FrameLayout>

1 FrameLayout, (ImageView) (TextView):

<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:src="@drawable/icon" android:scaleType="fitCenter" android:layout_height="fill_parent" android:layout_width="fill_parent"/> <TextView android:text="Learn-Android.com" android:textSize="24sp" android:textColor="#000000" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="center"/></FrameLayout>

2. LinearLayout - , , . , LinearLayout android:orientation. , , LinearLayout FrameLayout.

Palette . , :

<LinearLayout

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_centerVertical="true"

android:layout_alignRight="@+id/textView"

android:layout_alignEnd="@+id/textView"></LinearLayout>

. background. Resourses Project, System, Color . . - RGB ( , ). , 255 Red, Green 0 Blue. , # - 16- FFFF00, 0 256 16- (.2.3).

.2.3.

OK: , , (.2.4), ( ) :

android:background="#ffffff00">

 

.2.4.

, 3 (Button):

<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:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /></LinearLayout>

LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /></LinearLayout> </LinearLayout>

3. RelativeLayout - . :

android:layout_alignParentBottom ,

android:layout_alignParentLeft ,

android:layout_alignParentRight ,

android:layout_alignParentTop ,

android:layout_centerHorizontal ,

android:layout_centerInParent ,

android:layout_centerVertical .

. id .

android:layout_above ,

android:layout_below ,

android:layout_toLeftOf ,

android:layout_toRightOf ,

.

android:layout_alignBaseline baseline baseline ,

android:layout_alignBottom ,

android:layout_alignLeft ,

android:layout_alignRight ,

android:layout_alignTop ,

RelativeLayout.

<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/firstName" android:text="First Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/backbutton" /> <EditText android:id="@+id/editFirstName" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/firstName" android:layout_below="@id/backbutton"/> <EditText android:id="@+id/editLastName" android:width="100px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editFirstName" android:layout_alignLeft="@id/editFirstName"/> <TextView android:id="@+id/lastName" android:text="Last Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline = "@id/editLastName" android:layout_below="@id/editFirstName" /> </RelativeLayout>

TableLayout


TableLayout .
.
<TableRow>, <TableRow>.
android:layout_span.
<TableRow> , , android:layout_column

 

<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TableRow> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="column1" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="column2" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="column 3" android:textAppearance="?android:attr/textAppearanceMedium"/> </TableRow> <TableRow> <TextView android:id="@+id/textViewSpan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" span three column" android:layout_span = "3" android:textSize="23sp" android:textAppearance="?android:attr/textAppearanceMedium"/> </TableRow></TableLayout>



Alternate Layouts


Alternate Layouts . .
XML :

res/layout-land landscape UI
res/layout-port portrait UI
res/lauout-square square UI

res/lauout .

.

 


.
:

 

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />

 

xml res/values/
:

 

<?xml version="1.0" encoding="utf-8"?><resources> <style name="CodeFont" parent="@android:style/TextAppearance.Medium"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#00FF00</item> <item name="android:typeface">monospace</item> </style></resources>


, style.

 

<TextView style="@style/CodeFont" android:text="@string/hello" />

android

, android development

, android layout

}

, ImageView . , , . , , .

, FrameLayout . .

, . setMeasureAllChildren() true ( - android:measureAllChildren="true").





:


: 2016-11-24; !; : 447 |


:

:

, .
==> ...

1393 - | 1197 -


© 2015-2024 lektsii.org - -

: 0.029 .