Giving layouts with XML files is pretty easy (as some of you may know) If you don't have any idea about XML (as I was not having in my time) then don't worry about it let's get started here.
(This is my old post and some things are changed so you must have a look at this firstly. I am writing this line after 6 months since last edit of this post.)
The DESIGN section is selected by default that's why you are having phone on your screen.
Click on the "Text" section where you will find the hard code behind the layout present till now on the mobile screen.
Now we are going to talk about the things which are there in the layout file of our Activity.
These lines declare namespaces and you have to add these two lines to the the root widget of your layout for more information about these two you can refer to this link (or you can just take it as just syntex and focus on android).
Now, here some terms come which provide attributes like width, height, orientation of layouts, background color of layout etc. which are very important, you have to fill necessary ones and you can add some additional attributes for specific layout. Here we will consider some attributes which are really very important and you will use them most of the time in most of the views or Layouts(views will be covered).
(This is my old post and some things are changed so you must have a look at this firstly. I am writing this line after 6 months since last edit of this post.)
Firstly navigate to path app->src->main->res->layout->activity_main.java
So the folder named "layout" in the heirarchy contains all the layout XML files of different Activities. We will add layout of other Activities here only in later posts.
Open the file to edit
You are going to see how your layout is going to look like in phone.
As you add things you will have the things in phone.
So when you open an XML file which is intended to give various kind of layouts (in layout folder) you are going to see phone.
Look at the options below the section in which phone is displayed.
In this section you are going to see two section
"DESIGN" and "TEXT"
You are going to see how your layout is going to look like in phone.
As you add things you will have the things in phone.
So when you open an XML file which is intended to give various kind of layouts (in layout folder) you are going to see phone.
Look at the options below the section in which phone is displayed.
In this section you are going to see two section
"DESIGN" and "TEXT"
The DESIGN section is selected by default that's why you are having phone on your screen.
Click on the "Text" section where you will find the hard code behind the layout present till now on the mobile screen.
Now we are going to talk about the things which are there in the layout file of our Activity.
In this post we will learn about how to use some very common things(views).
You can see a term "RelativeLayout" out there with opening and closing angle brackets
First note that some other layouts other than "Relative Layout" out there.
So commonly used Layouts are
1.LinearLayout
2.RelativeLayout
3.TableLayout
4.FrameLayout
5.DrawerLayout
We make selection of Widgets(Layouts) according to our use.
These Layouts are the widgets which are responsible for arranging the Views within it. For example, if we are displaying simple text then we have to add it in this type of widgets or Layout According to our use(it will be more clear).
We will use each one of them
For this time replace the term "Relative" by "Linear"(we will be using Linear Layout here).
The two lines after the name of root layout
1.xmlns:android="http://schemas.android.com/apk/res/android"
2.xmlns:tools="http://schemas.android.com/tools"
These lines declare namespaces and you have to add these two lines to the the root widget of your layout for more information about these two you can refer to this link (or you can just take it as just syntex and focus on android).
Now, here some terms come which provide attributes like width, height, orientation of layouts, background color of layout etc. which are very important, you have to fill necessary ones and you can add some additional attributes for specific layout. Here we will consider some attributes which are really very important and you will use them most of the time in most of the views or Layouts(views will be covered).
android:layout_width="match_parent"android:layout_height="match_parent"
We have to add "android:" attribute most of the time.
As you can see these both are used to give Layout's width and height.
"Cover up attributes" :These attributes decide the total cover up of particular view or Layout on screen
There are two type of cover up attributes
1.match_parent
2.wrap_content
Here The Linear Layout is our root or parent widget and having match_parent attribute our widget is going to cover the entire screen and if same attribute(match_parent) is given to views within it, will also cover the entire screen as well or we can say it will have same width and height as its parent do.
While in case of wrap_content attribute(android:layout_height="wrap_content") our layout will only cover the part of screen in which its contents are adjusted.
Now, come to the term TextView,
This is a simple view which is used to display some text on screen with some necessary attributes and/or addition attributes.
That's all for now we will have explanation on some other attributes and proper elaboration of TextView in very next post.
No comments:
Post a Comment