Free Download Software and Android Tutorials

Wednesday, July 1, 2015

Tutorial Android studio: knowing the types of layouts in the android part 2

Tutorial Android studio this time is a continuation of a previous article that is familiar with the types of layouts on android. In the previous article we already know the three types of layouts that Linear Layout, Table Layout and Frame Layout. This time we will discuss is the relative layout which is the most flexible layout, because you can place objects anywhere on the layout to your liking. In the relative layout you can use attributes above, below, left, and right. In addition, the relative advantages of this layout is that if you change the size of the screen, then the position of objects that are in relative layout is not dependent on the screen resolution of your android device. The picture below is an example of relative layout program along with the source code, please you learn more in depth.


Tutorial Android studio: knowing the types of layouts in the android part 2

This is the program's source code from the image above for an example of relative layout.

<?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:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/btnButton1"
       
android:text="First Button"/>

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/btnButton2"
       
android:text="Second Button"
       
android:layout_toRightOf="@+id/btnButton1"/>

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/btnButton3"
       
android:text="Third Button"
       
android:layout_below="@+id/btnButton1"/>

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/textView1"
       
android:layout_below="@+id/btnButton3"
       
android:layout_marginTop="90dp"
       
android:text="User:"
       
android:textAppearance="?android:attr/textAppearanceLarge"/>

    <
EditText
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/editText1"
       
android:layout_alignParentRight="true"
       
android:layout_alignTop="@+id/textView1"
       
android:layout_toRightOf="@+id/btnButton3"/>

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:id="@+id/btnSubmit"
       
android:layout_alignParentRight="true"
       
android:layout_below="@+id/editText1"
       
android:text="Submit"/>
</
RelativeLayout>

If the source code of the program run using the emulator genymotion or other android device, then the result is as shown below.

Tutorial Android studio: knowing the types of layouts in the android part 2

From the above we can take the conclusion that the relative layout we can easily adjust each object e.g. only the second button is located right next to the first button, the third button is located below the first button and so on. Thus the discussion about the layout on the android, I hope to here you can understand it well so that later when making an application does not run into trouble again because it already has a basic knowledge of different types of layouts on android. Next I will discuss about the attributes of the layout.

Attribute layout

Attribute freely can be interpreted as or an inherent properties of an object. Attribute layout means is the inherent nature of an object, while it was on a layout usually consists of many objects. Objects on the android can be TextView, EditText, Button, and many others. The following attributes of the layout found on android, which is generally a lot in common sense usability.

Android:orientation
Orientation is an attribute xml layout containing object orientation either horizontal or vertical. The following example xml layout of objects arranged vertically.

android:orientation="vertikal"

android:layout_width and android:layout_height
layout_width and layout_height an attribute that contains the width and height of the object. Its value can be a constant size or numbers. Here's an example of the attribute layout_width and layout_height

android:layout_widht=”wrap_content”
android:layout_height=”100 dp”

android:id
Each object in the android must have a unique id that serves to the identity of the object that will be used in a program, the following example.

android:id=”@+id/button1”

android:text and android:textSize
Objects in the android like Button, TextView, EditText, and other form of writing has the attributes of text and textsize. Attribute text contains fonts or writings contained in the object, while textsize contains the font size. Text attributes can be filled directly by writing or with a string variable resource.


android:text=”@string/my_button_text”
android:textSize=”18sp”

android:layout_gravity
layout_gravity attribute is the layout of objects on the layout surrounding child (parent). Layout_gravity constants can be filled as in the table.


android:layout_gravity=”left”

android:layout_weight
layout_weight attribute is used to determine the amount of layout area in accordance with the ratio of weight to the layout, usually these attributes are the type of linear layout.


android:layout_weight=”2”

android:padding
Padding attribute of an object is a margin of restrictions left, right, up, and down



android:paddingLeft=”16dp”
android:paddingRight=”16dp”
android:paddingTop=”16dp”
android:paddingBottom=”16dp”

That some attribute to the layout in android, which are then often you use when designing a layout design to produce an attractive appearance and also user friendly course. Hopefully this article can give you new benefits to learn an android programming language using android studio.

Download Article in PDF







Tutorial Android studio: knowing the types of layouts in the android part 2 Rating: 4.5 Diposkan Oleh: Unknown

0 comments:

Post a Comment