Sunday, 22 March 2020

Difference Between Linear Layout and Relative Layout in Android



Relative Layout:
A relative layout displays its views relative to one another or relative to parent , so order is not that important. You can define the top most view at the end of the layout and provide details to show it on top left. The following attributes are used to define relative layouts:
  1. Position relative to Parent: You can align a view relative to parent using alignParentTop, centerHorizontal etc.
  2. Position relative to other views: You can align a view relative to another view using above, below, toLeftOf etc.
  3. Margins: You can provide margins using marginTop, marginLeft etc.
Linear Layout:
A linear layout displays its views next to each other either vertically or horizontally. So, if you define views in a row, they will be displayed one after the other. You need to specify orientation to define whether layout is vertical or horizontal. The following attributes are used to define linear layouts:
  1. Weight: It specifies how much space each view spans relative to others. For example, in an e-mail application, you can give less weight to ‘To’ and ‘Subject’, and more weight to ‘Message’.
  2. Gravity: It defines placement of a view’s contents. You can decide whether it should be displayed on top, center or bottom.
  3. Layout Gravity: It defines the placement of the view itself.

Importance of Android manifest file

Every project in Android includes AndroidManifest.xml, file which is stored in the root directory of its project hierarchy. The manifest file is an important part of our application because it defines the structure and metadata of our application, its components, and its requirements.
This file includes nodes for each of the Activities, Services, Content Providers and Broadcast Receiver that make the application and it also includes  Intent Filters and Permissions, which determines how activities co-ordinate with each other and other applications.
The manifest file also specifies the application metadata, which includes its icon, version number, themes etc.
A  manifest node looks like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pkg.myapp"
android:versionCode="1"
android:versionName="0.9 Beta"
[....manifest nodes....] 
</manifest> 
uses-sdk– It is used to define a minimum and maximum SDK version that must be available on a device so that our application function properly, and target SDK for which it has been designed .


<uses-sdk android:minSdkVersion=”6”
        android:targetSdkVersion=”15”/>

application– A manifest can contain only one application node. It uses attributes to specify the metadata for your application (including its title, icon and theme). During development we should include a debuggable attribute set to true to enable debugging, then be sure to disable it for your release builds.

<application android:icon="@drawable/icon"
             android:theme="@android:style/Theme.Light"
             android:name=".MyApplicationClass"
             android:debuggable="true">
             [....application nodes.....]

</application>

What are apk files and how to deploy apk files

Apk Files:An Android Package Kit (APK for short) is the package file format used by the Android operating system for distribution and installation of mobile applications. Just like Windows (PC) systems use an .exe file for installing software, the APK does the same for Android.

Once your Android application is signed, you can deploy it to emulators and devices using the adb.exe (Android Debug Bridge) tool (located in the platform-tools folder of the Android SDK).
Using the command prompt in Windows, navigate to the <Android_SDK>\platform-tools folder. 
To install the application to an emulator/device (assuming the emulator is currently up and running or a device is currently connected), issue the following command:
adb install "C:\Users\abc\Desktop\Practical1.apk"