Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.

Slides:



Advertisements
Similar presentations
User Interface Classes.  Design Principles  Views & Layouts  Event Handling  Menus  Dialogs.
Advertisements

User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Layout and Control in UI The user interface (UI) is the graphical interface user can see and interact with your app comprising UI controls like textbox,
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Selection Widgets Các Widget cho phép chọn Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright ©
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android: Layouts David Meredith
Android Layouts. Layouts Define the user interface for an activity Layouts are defined in.xml files – within /res/layout folder – different layout can.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Android Fundamentals and Components Kris Secor Mobile Application Development.
Package org.androidtown.database.query; import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;
CHAP 10. 고급 위젯. © 2012 생능출판사 All rights reserved 어댑터 뷰 어댑터 뷰 (AdapterView) 는 배열이나 파일, 데이터 베이스에 저장된 데이터를 화면에 표시할 때 유용한 뷰.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
ListView.
Android - Broadcast Receivers
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Import import android.graphics.Bitmap; import android.widget.ImageView;
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.
ListView and ExpandableListView
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Http :// developer. android. com / guide / topics / fundamentals. html.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android 9: Layouts Kirk Scott.
Lab7 – Appendix.
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
CS499 – Mobile Application Development
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
Adapting to Display Orientation
GUI Programming Fundamentals
Further android gui programming
Mobile Software Development for Android - I397
Android Basic XML Layouts
Android Introduction Hello World.
Android External Resources
Mobile Application Development BSCS-7 Lecture # 8
Android 9: Layouts Kirk Scott.
Android List-Based Selection Widgets
Android Widgets 1 7 August 2018
Android Introduction Hello Views Part 1.
ITEC535 – Mobile Programming
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Lists and Fragments
CMPE419 Mobile Application Development
Building User Interfaces Basic Applications
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Note Q) How to format code in Enclipse? A) Ctrl + i
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Adding Components to Activity
Korea Software HRD Center
CMPE419 Mobile Application Development
Introduction to Android
Lasalle-App Tecnología Móvil.
Android Sensor Programming
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1

Android - UI Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 2

example of XML file having LinearLayout <?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:text="This is a Button" /> <!-- More GUI components go here --> </LinearLayout> Activity.onCreate() callback implementation public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Android Layout Types Sr.No Layout & Description 1 Linear Layout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. 2 Relative Layout RelativeLayout is a view group that displays child views in relative positions. 3 Table Layout TableLayout is a view that groups views into rows and columns. 4 Absolute Layout AbsoluteLayout enables you to specify the exact location of its children. 5 Frame Layout The FrameLayout is a placeholder on screen that you can use to display a single view. 6 List View ListView is a view group that displays a list of scrollable items. 7 Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Attribute & Description Android Linear Layout Android LinearLayout is a view group that aligns all children in either vertically or horizontally. Sr.No Attribute & Description 1 android:id. 2 android:baselineAligned 3 android:baselineAlignedChildIndex 4 android:divider 5 android:gravity 6 android:orientation 7 android:weightSum <?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" > <Button android:id="@+id/btnStartService" android:layout_width="270dp" android:layout_height="wrap_content" android:text="start_service"/> <Button android:id="@+id/btnPauseService" android:text="pause_service"/> <Button android:id="@+id/btnStopService" android:text="stop_service"/> </LinearLayout> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Android Linear Layout - Output 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Attribute & Description Android Relative Layout RelativeLayout Attributes RelativeLayout.LayoutParams Sr.No. Attribute & Description 1 android:layout_above 2 android:layout_alignBottom 3 android:layout_alignLeft 4 android:layout_alignParentBottom 5 android:layout_alignParentEnd 6 android:layout_alignParentLeft 7 android:layout_alignParentRight 8 android:layout_alignParentStart 9 android:layout_alignParentTop 10 android:layout_alignRight 11 android:layout_alignStart 12 android:layout_alignTop 13 android:layout_below 14 android:layout_centerHorizontal 15 android:layout_centerInParent 16 android:layout_centerVertical 17 android:layout_toEndOf 18 android:layout_toLeftOf 19 android:layout_toRightOf 20 android:layout_toStartOf 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Android Relative Layout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="16dp" android:paddingRight="16dp" > <EditText android:id="@+id/name" android:layout_height="wrap_content" android:hint="@string/reminder" /> <LinearLayout android:orientation="vertical" android:layout_alignParentStart="true" android:layout_below="@+id/name"> <Button android:layout_width="wrap_content" android:text="New Button" android:id="@+id/button" /> android:id="@+id/button2" /> </LinearLayout> </RelativeLayout> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Attribute & Description Android Table Layout TableLayout Attributes Sr.No. Attribute & Description 1 android:id 2 android:collapseColumns 3 android:shrinkColumns 4 android:stretchColumns 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Android Table Layout 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS <TableRow> <TextView android:text="Last Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" /> <EditText android:width="100px" android:layout_height="wrap_content" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"> <RatingBar android:id="@+id/ratingBar" android:layout_column="2" /> android:layout_height="fill_parent"/> <Button android:text="Submit" android:id="@+id/button" </TableLayout> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow <TextView android:text="Time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" /> <TextClock android:id="@+id/textClock" android:layout_column="2" /> </TableRow> <TableRow> android:text="First Name" <EditText android:width="200px" android:layout_height="wrap_content" /> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Attribute & Description Android Frame Layout FrameLayout Attributes Sr.No Attribute & Description 1 android:id 2 android:foreground 3 android:foregroundGravity 4 android:measureAllChildren 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Android Frame Layout res/values/strings.xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:src="@drawable/ic_launcher" android:scaleType="fitCenter" android:layout_height="250px" android:layout_width="250px"/> <TextView android:text="Frame Demo" android:textSize="30px" android:textStyle="bold" android:layout_height="fill_parent" android:gravity="center"/> </FrameLayout> res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">demo</string> <string name="action_settings">Settings</string> </resources> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Attribute & Description Android List View Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database. The ListView and GridView are subclasses of AdapterView The common adapters are ArrayAdapter,Base Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListAdapter ListView Attributes Sr.No Attribute & Description 1 android:id 2 android:divider 3 android:dividerHeight 4 android:entries 5 android:footerDividersEnabled 6 android:headerDividersEnabled 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

ArrayAdapter src/com.example.ListDisplay/ListDisplay.java. ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.ListView,StringArray); Once you have array adapter created, then simply call setAdapter() on your ListView object as follows − ListView listView = (ListView) findViewById(R.id.listview); listView.setAdapter(adapter); src/com.example.ListDisplay/ListDisplay.java. res/layout/activity_main.xml package com.example.ListDisplay; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.ListView; public class ListDisplay extends Activity { // Array of strings... String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry", "WebOS","Ubuntu","Windows7","Max OS X"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, mobileArray); ListView listView = (ListView) findViewById(R.id.mobile_list); listView.setAdapter(adapter); } <LinearLayout 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:orientation="vertical" tools:context=".ListActivity" > <ListView android:id="@+id/mobile_list" android:layout_height="wrap_content" > </ListView> </LinearLayout> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

<?xml version="1.0" encoding="utf-8"?> <resources> res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">ListDisplay</string> <string name="action_settings">Settings</string> </resources> res/layout/activity_listview.xml <?xml version="1.0" encoding="utf-8"?> <!-- Single List Item Design --> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dip" android:textSize="16dip" android:textStyle="bold" > </TextView> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Attribute & Description Android Grid View GridView Attributes Sr.No Attribute & Description 1 android:id 2 android:columnWidth 3 android:gravity 4 android:horizontalSpacing 5 android:numColumns 6 android:stretchMode 7 android:verticalSpacing res/layout/activity_main.xml <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">HelloWorld</string> <string name="action_settings">Settings</string> </resources> src/com.example.helloworld/MainActivity.java. package com.example.helloworld; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.GridView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ImageAdapter(this)); } 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

src/com.example.helloworld/ImageAdapter.java file − public long getItemId(int position) { return 0; } // create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(8, 8, 8, 8); else { imageView = (ImageView) convertView; imageView.setImageResource(mThumbIds[position]); return imageView; // Keep all Images in array public Integer[] mThumbIds = { R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7, R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_6, R.drawable.sample_7 }; package com.example.helloworld; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; public class ImageAdapter extends BaseAdapter { private Context mContext; // Constructor public ImageAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds.length; public Object getItem(int position) { return null; 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS

Thank You 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS