Learn UI pagination in Android

The main building block for creating the user interface is a View object that is created from the View class and occupies a rectangular area on the screen and is responsible for handling events.

View is a base class for widgets used to create interactive UI components such as buttons, text fields, and more.

ViewGroup is also a subclass of View and provides you with an invisible container in which you can store other views or other ViewGroups, as well as their pagination features.

On Android ; We have different paginations in which the ViewGroup class subclasses are located. A typical pagination actually defines the visual structure of the Android user interface and can be created either at runtime using the View / ViewGroup objects, or you can define your pagination using a simple main_layout XML file. Which is located in the res / layout folder of your project.

 

Paging parameters

This tutorial; It’s more about creating your own UI based on the layouts defined in the XML file. A pagination may include any type of widget, such as buttons, labels; Include text boxes and the like. The following is a simple example of an XML file with linear pagination:

<? xml version = ”1.0 ″ encoding =” utf-8 ″?>

<LinearLayout xmlns: android = ”http://schemas.android.com/apk/res/android”

android: layout_width = ”fill_parent”

android: layout_height = ”fill_parent”

android: orientation = ”vertical”>

<TextView android: id = ”@ + id / text”

android: layout_width = ”wrap_content”

android: layout_height = ”wrap_content”

android: text = ”This is a TextView” />

<Button android: id = ”@ + id / button”

android: layout_width = ”wrap_content”

android: layout_height = ”wrap_content”

android: text = ”This is a Button” />

<! – More GUI components go here ->

</LinearLayout>

When your pagination was created; As shown below; You can source pagination from your application code; Upload your Activity.onCreat () call to implement the callback .

public void onCreate (Bundle savedInstanceState) {

super.onCreate (savedInstanceState);

setContentView (R.layout.activity_main);

}

Types of Android pagination

There are a number of paginations and layouts provided by Android and you can use them in most Android applications to create different views, perspectives and emotions.

No. Sr Layout and description
1 Linear paginationLinear pagination is a representation of a group of elements that aligns all child views in a single direction horizontally or vertically.
۲ Dependent paginationDependent pagination is a representation of a group of elements that display child views in dependent situations.
3 Tabular paginationTabular pagination is a view that groups views in a column and row.
4 Absolute paginationAbsolute pagination enables you to determine the true position of its children.
5 Framework paginationFrame pagination is a screen placeholder that you can use to display a single view.
6 View a list (ListView)List pagination is a group of views that displays a list of navigable items.
7 Grydvyv (GridView)Gridview is a layout in which items are displayed in a two-dimensional navigable grid.

Pagination features

Each pagination has a unique set of features that define the visual features of that pagination. Here are some common features between all paginations as well as features that are paginated specifically and uniquely; Is brought. The table below covers common pagination features that are common to all paginations.

Row Features and its explanation
1 android: idThis ID specifies the view only.
۲ android: layout_widththis feature; Specifies the width of the pagination.
3 android: layout_heightthis feature; Specifies the length of the pagination.
4 android: layout_marginTopThis feature shows the extra distance from the top of the page.
5 android: layout_marginBottomThis feature shows the extra distance from the bottom of the pagination.
6 android: layout_marginleftThis feature shows the extra distance to the left of the pagination.
7 android: layout_marginleftThis feature shows the extra distance to the right of the pagination.
8 android: layout_gravityThis feature specifies how many child views are placed.
9 android: layout_weightThis feature specifies how much extra paging space should be allocated to the View.
10 android: layout_xThis property specifies the x pagination coordinates.
۱۱ android: layout_yThis property specifies the y coordinates of the pagination.
۱۲ android: layout_widthThis feature is paging width.
13 android: layout_widthThis feature is paging width.
۱۴ android: PaddingLeftThis feature is the left padding distance for pagination.
۱۵ android: PaddingRightThis feature is the right padding distance for pagination.
۱۶ android: PaddingTopThis feature has a high padding distance for pagination.
۱۷ android: PaddingBottomThis feature has a low padding distance for pagination.

Here are the length and width of the view / pagination dimensions, which can be specified in terms of the following: dp (density-independent pixels); sp (scale-independent pixels), pt (dots per inch), px (pixels), mm (mm), and finally in (inches).

You can specify width and height with precise measurements, but you often use the following constants to adjust width and height.

  • android:; layout_width = wrap_content tells your view to resize itself to the dimensions its content requires.
  • android:; layout_width = fill_parent tells your view that it is the size of its parent’s View; Grow up.

The gravity property plays an important role in positioning the view object and can adopt one or more of the following constant values ​​(separated by ‘|’).

Fixed the amount of Explanation
Top ۰۳۰ Places the object at the top of the section containing it; Without changing its size.
Bottom Places the object at the bottom of the section containing it; Without changing its size.
Left Places the object to the left of the section containing it; Without changing its size.
Right Places the object to the right of the section containing it; Without changing its size.
Vertical in the center (center_vertical) Places the object on the vertical axis of the section containing it; Without changing their size.
Fill_vertical (vertical fill of page) Increases the size of the object vertically if needed; To fully cover the part it contains.
fill_horizontally (fill page horizontally) Increases the size of the object horizontally if needed; To fully cover the part it contains.
Center Places the object in the center of the section containing it, which is at the intersection of the vertical and horizontal axes of the plane; Without changing its size.
clip_vertical (vertical cut) Another option that can be adjusted to bring the top and / or bottom edges of the child to the borders of the section it contains; To send. This cut will be based on vertical gravity: a high gravity will cut the bottom edge, a low gravity will cut the top edge, or it will not cut either edge.
clip_horizontal (horizontal cut) Another option that can be adjusted to bring the left and / or right edges of the child to the borders of the section it contains; To send. This cut will be based on horizontal gravity: a left gravity will cut the right edge, a right gravity will cut the left edge, or it will not cut either edge.
Start Moves the object to the beginning of the section containing it; Without changing its size.
End Moves the object to the end of the section containing it; Without changing its size.

View identification

A view object may have a specific identifier (ID) assigned to it that identifies that view exclusively within the tree. The syntax for an ID within an XML tag is as follows:

android: id = ”@ + id / my_button”

The following is a brief description of the @, + and signs.

  • The @ symbol that appears at the beginning of the string; Indicates that the XML parser must parse and extend the rest of the ID string, then specify it as an ID source.
  • The plus sign (+) means a new resource name to be created and added to our resource. To create an example of a view object and download it from pagination; Use the following coding:

Button myButton = (Button) findViewById (R.id.my_button);

Leave a Reply

Your email address will not be published. Required fields are marked *