<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.android.happybirthday.MainActivity">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Default Constraint Layout Android SDK
Discussion about Constraint Layout
Before starting on the next video, we want to bring to your attention a new feature in new Android Studio - Constraint Layout - that may require you to make some code modifications to the steps you see in the following videos.
All of this matters to you because the new project templates in Android Studio now use
If you want to understand more about the great features that
Keeping up with the changes
Google is constantly improving the Android platform and adding new features. This is great for you as a developer, but it makes learning harder sometimes. Recently Google releasedConstraintLayout
; a tool that makes it super fast to create responsive UIs with many different types of components. ConstraintLayout
is a great tool to have on the sleeve, but for this class, we will use RelativeLayout
, LinearLayout
simpler.All of this matters to you because the new project templates in Android Studio now use
ConstraintLayout
as default, which makes the code you see on your computer a bit different from what is on the screen.Current Layout File
In the new versions of Android Studio, after choosing theEmpty Activity
template, the layout file app/src/main/res/layout/activity_main.xml
will look like this:<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.udacity.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintTop_toTopOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
app:layout_constraintBottom_toBottomOf="@+id/activity_main" />
</android.support.constraint.ConstraintLayout>
Note the use of ConstraintLayout
, and that TextView
has a list of limiters that position it within ConstraintLayout
.Modify the Layout File
Unlike the above code, our videos and start code assume that the template looks more like the following, using as the root of the view aRelativeLayout
:<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.udacity.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
When you create your new project, go to app/src/main/res/layout/activity_main.xml
and copy and paste the above code. Then you're ready to go!If you want to understand more about the great features that
ConstraintLayout
provides, check out the documentation at: https://developer.android.com/studio/write/layout-editor.htmlCoffee Break Challenge Udacity Android For Beginers finding error in code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To Ben"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Happy Birthday"
android:textSize="34sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ocean"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="From, Lyla"
android:textSize="24sp"/>
</LinearLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To Ben"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Happy Birthday"
android:textSize="34sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ocean"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="From, Lyla"
android:textSize="24sp"/>
</LinearLayout>
Installation Guide: Windows
Installation Guide: Windows
ForMac installation instructions, go to the next page.Install Android Studio
Navigate here, to the Android developers site to install Android Studio. This page will automatically detect your operating system.Accept the terms and conditions to start the download. Double-click the downloaded file and follow all the prompts. Open the downloaded file, and follow the Android Studio Setup Wizard. Accept the defaults configuration for all steps.
When you reach this screen, make sure that all components are selected.
Setup Wizard
After finishing the install, the Setup Wizard will download and install some additional components. Be patient, this might take some time depending on your internet speed.Install Finished!
When you are finished, you will see this window:Padding On The Sides And Want Margin At All The Sides Of The Device
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:src="@drawable/ocean"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
<TextView
android:text="You're invited!"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="45sp"
android:background="#009688"/>
<TextView
android:text="Bonfire at the beach"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="24sp"
android:background="#009688"
android:paddingBottom="16dp"
android:paddingLeft="16dp"/>
</LinearLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:src="@drawable/ocean"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
<TextView
android:text="You're invited!"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="45sp"
android:background="#009688"/>
<TextView
android:text="Bonfire at the beach"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="24sp"
android:background="#009688"
android:paddingBottom="16dp"
android:paddingLeft="16dp"/>
</LinearLayout>
Linear Layout To Relative Layout To Form List Using A Image View And Text View
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/beach_Image_View"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="centerCrop"
android:src="@drawable/ocean" />
<TextView
android:id="@+id/pebble_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/beach_Image_View"
android:text="Pebble Beach"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="@+id/California_Text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/beach_Image_View"
android:layout_below="@id/pebble_text_View"
android:text="California"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:id="@+id/ten_Text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/beach_Image_View"
android:layout_below="@id/California_Text_View"
android:text="10 miles away"
android:textAppearance="?android:textAppearanceSmall" />
</RelativeLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/beach_Image_View"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="centerCrop"
android:src="@drawable/ocean" />
<TextView
android:id="@+id/pebble_text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/beach_Image_View"
android:text="Pebble Beach"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="@+id/California_Text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/beach_Image_View"
android:layout_below="@id/pebble_text_View"
android:text="California"
android:textAppearance="?android:textAppearanceSmall" />
<TextView
android:id="@+id/ten_Text_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/beach_Image_View"
android:layout_below="@id/California_Text_View"
android:text="10 miles away"
android:textAppearance="?android:textAppearanceSmall" />
</RelativeLayout>
Relative Layout Of Text View With Respect To Other text Views
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/lyla_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="24sp"
android:text="Lyla" />
<TextView
android:id="@+id/me_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/lyla_text_view"
android:textSize="24sp"
android:text="Me" />
<TextView
android:id="@+id/natalie_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_above="@id/lyla_text_view"
android:text="Natalie" />
<TextView
android:id="@+id/jennie_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textSize="24sp"
android:text="Jennie" />
<TextView
android:id="@+id/omoju_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@id/jennie_text_view"
android:textSize="24sp"
android:text="Omoju" />
<TextView
android:id="@+id/amy_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@id/omoju_text_view"
android:textSize="24sp"
android:text="Amy" />
<TextView
android:id="@+id/ben_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:text="Ben" />
<TextView
android:id="@+id/kunal_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ben_text_view"
android:textSize="24sp"
android:text="Kunal" />
<TextView
android:id="@+id/kagure_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/ben_text_view"
android:textSize="24sp"
android:text="Kagure" />
</RelativeLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/lyla_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="24sp"
android:text="Lyla" />
<TextView
android:id="@+id/me_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/lyla_text_view"
android:textSize="24sp"
android:text="Me" />
<TextView
android:id="@+id/natalie_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_above="@id/lyla_text_view"
android:text="Natalie" />
<TextView
android:id="@+id/jennie_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textSize="24sp"
android:text="Jennie" />
<TextView
android:id="@+id/omoju_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@id/jennie_text_view"
android:textSize="24sp"
android:text="Omoju" />
<TextView
android:id="@+id/amy_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@id/omoju_text_view"
android:textSize="24sp"
android:text="Amy" />
<TextView
android:id="@+id/ben_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:text="Ben" />
<TextView
android:id="@+id/kunal_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ben_text_view"
android:textSize="24sp"
android:text="Kunal" />
<TextView
android:id="@+id/kagure_text_view"
android:background="#009688"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/ben_text_view"
android:textSize="24sp"
android:text="Kagure" />
</RelativeLayout>
Relative Layout, Parent View, Child View.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="Happy" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="To" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="You...!!" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="Birthday" />
</RelativeLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="Happy" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="To" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="You...!!" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#009688"
android:textSize="34sp"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceLarge"
android:text="Birthday" />
</RelativeLayout>
Linear Layout , Layout Weight, Type Of View
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray">
<ImageView
android:src="@drawable/ocean"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
<TextView
android:text="VIP List"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#4CAF50"
android:textSize="24sp" />
<TextView
android:text="Kunal"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffa726"
android:textSize="24sp" />
<TextView
android:text="Kagure"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffff"
android:textSize="24sp" />
<TextView
android:text="Lyla"
android:textColor="#f44336"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#000000"
android:textSize="24sp" />
</LinearLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray">
<ImageView
android:src="@drawable/ocean"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
<TextView
android:text="VIP List"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#4CAF50"
android:textSize="24sp" />
<TextView
android:text="Kunal"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffa726"
android:textSize="24sp" />
<TextView
android:text="Kagure"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffff"
android:textSize="24sp" />
<TextView
android:text="Lyla"
android:textColor="#f44336"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#000000"
android:textSize="24sp" />
</LinearLayout>
Subscribe to:
Posts (Atom)
కరోనా కోవిడ్ -19 గురించి ఏ వికీపీడియా మీకు చెప్పలేము?
కరోనా కోవిడ్ -19 గురించి ఏ వికీపీడియా మీకు చెప్పలేము? మిమ్మల్ని మీరు రక్షించుకోండి Your మీ చేతులను తరచుగా కడగాలి Eyes మీ కళ్ళు, న...
-
An intriguing report this week suggests that Samsung may be imitating the iPhone range when the Galaxy Note 8 hits the stores. With Samsun...