You are on page 1of 13

[ 2CEIT509 MOBILE APPLICATION DEVELOPMENT]

Practical: 6

AIM- Create following UI by using RelativeLayout, LinearLayout,


ConstraintLayout in one android Application. Create three activities
for each layout & use BottomNavigationBar & Explicit Intent to move
from one activity to another activity. Don't use RelativeLayout in
ConstraintLayout, LinearLayout in ConstraintLayout and vice versa.

Submitted By: Divyesh Patel


Enrollment number: 19012011111

Department of Computer
Engineering/Information Technology
Practical: 6
Create following UI by using RelativeLayout, LinearLayout, ConstraintLayout in one android
Application. Create three activities for each layout & use BottomNavigationBar & Explicit Intent to move
from one activity to another activity. Don't use RelativeLayout in ConstraintLayout, LinearLayout in
ConstraintLayout and vice versa.

MainActivity.kt :-
package com.example.p_6_19012011111

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.android.material.bottomnavigation.BottomNavigationView

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val bottom1:BottomNavigationView = findViewById(R.id.navigation)

bottom1.setOnItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedLi
stener {
Log.d("MainActivity","inside home")
when(it.itemId){

R.id.home2->{
Log.d("Second","inside Second")
startActivity(Intent(this,constraint::class.java))

}
R.id.home3->{
Log.d("ThirdActivity","inside third")
startActivity(Intent(this,relative::class.java))
}
}
return@OnNavigationItemSelectedListener true
})
}
}
private fun
BottomNavigationView.setOnNavigationItemReselectedListener(onNavigationItemSelect
edListener: BottomNavigationView.OnNavigationItemSelectedListener) {

Divyesh Patel 19012011111


Practical: 6

Constraint.kt :-
package com.example.p_6_19012011111

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.android.material.bottomnavigation.BottomNavigationView

class constraint : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_constrain)
val bottom1: BottomNavigationView =findViewById(R.id.navigation)

bottom1.setOnItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedLi
stener {
Log.d("MainActivity","inside home")
when(it.itemId){
R.id.home1->{

Log.d("MainActivity","inside home")

startActivity(Intent(this,MainActivity::class.java))

R.id.home3->{
Log.d("ThirdActivity","inside third")
startActivity(Intent(this,relative::class.java))
}
}
return@OnNavigationItemSelectedListener true
})
}
}

Divyesh Patel 19012011111


Practical: 6

Relative.kt :-
package com.example.p_6_19012011111

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.android.material.bottomnavigation.BottomNavigationView

class constraint : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_constrain)
val bottom1: BottomNavigationView =findViewById(R.id.navigation)

bottom1.setOnItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedLi
stener {
Log.d("MainActivity","inside home")
when(it.itemId){
R.id.home1->{

Log.d("MainActivity","inside home")

startActivity(Intent(this,MainActivity::class.java))

R.id.home3->{
Log.d("ThirdActivity","inside third")
startActivity(Intent(this,relative::class.java))
}
}
return@OnNavigationItemSelectedListener true
})
}
}

Divyesh Patel 19012011111


Practical: 6

activity_main.xml :-

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">

<LinearLayout
android:layout_weight="0.8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="@drawable/download"
android:scaleType="fitXY"
android:contentDescription="TODO" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="130dp"
app:cardBackgroundColor="#333333"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:cardCornerRadius="20dp"
android:layout_marginTop="-60dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher_foreground"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Divyesh Patel 19012011111
Practical: 6
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Linear Layout"
android:textSize="30dp"
android:textColor="#FFFFFF"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Linear Layout"
android:textSize="20dp"
android:textColor="#FFFFFFFF"/>

</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_marginBottom="20dp"
app:cardBackgroundColor="#333333"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="10dp"
android:layout_marginTop="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher_foreground"/>
Divyesh Patel 19012011111
Practical: 6

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is Practical-6 of MAD."
android:textColor="#ffffff"
android:textSize="20dp"/>

</LinearLayout>
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/download1" />

</LinearLayout>
</androidx.cardview.widget.CardView>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_weight="0.2"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/purple_500"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:menu="@menu/navigation_bar"/>

</LinearLayout>

Activity_relative.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout 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"
Divyesh Patel 19012011111
Practical: 6
android:layout_height="match_parent"
tools:context=".relative">

<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="fitXY"
android:src="@drawable/download" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:cardBackgroundColor="#333333"
app:cardCornerRadius="20dp"
android:layout_marginTop="200dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="250dp"
android:src="@drawable/ic_launcher_foreground"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="100dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relative layout"
android:textSize="30dp"
android:textColor="#FFFFFF"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"/>

<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="50dp"
android:text="This is a Relative Layout"
android:textColor="#FFFFFFFF"
android:textSize="18dp" />

</RelativeLayout>
Divyesh Patel 19012011111
Practical: 6

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="340dp"
android:layout_marginRight="10dp"
app:cardBackgroundColor="#333333"
app:cardCornerRadius="10dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="250dp"
android:src="@drawable/ic_launcher_foreground"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:layout_marginBottom="140dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="80dp"

android:text="This is a Practical-6 of MAD."


android:textColor="#FFFFFFFF"
android:textSize="20dp" />

</RelativeLayout>

<View
android:layout_marginTop="120dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/download1"/>

</androidx.cardview.widget.CardView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="0dp"
android:background="@color/purple_500"
Divyesh Patel 19012011111
Practical: 6
android:foregroundGravity="bottom"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
android:id="@+id/navigation"
app:menu="@menu/navigation_bar"/>

</RelativeLayout>

Activity_constrain.xml

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.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=".constraint">

<ImageView
android:id="@+id/ab"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="fitXY"
android:src="@drawable/download"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.cardview.widget.CardView
android:id="@+id/cv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="195dp"
android:layout_marginBottom="20dp"
app:cardBackgroundColor="#333333"
app:layout_constraintBottom_toTopOf="@+id/cv2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.448"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView

Divyesh Patel 19012011111


Practical: 6
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_foreground"/>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_marginLeft="100dp">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Constraint layout"
android:textColor="#FFFFFF"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="271dp"
android:layout_height="60dp"
android:text="This is a Constraint Layout"
android:textSize="20dp"
android:textColor="#FFFFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/cv2"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginTop="10dp"
app:cardBackgroundColor="#333333"
app:cardCornerRadius="20dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.481"
app:layout_constraintStart_toStartOf="parent"
Divyesh Patel 19012011111
Practical: 6
app:layout_constraintTop_toBottomOf="@id/cv1">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="250dp"
android:src="@drawable/ic_launcher_foreground"/>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="253dp"
android:layout_height="105dp"
android:layout_marginEnd="4dp"
android:text="This is a Practical-6 of MAD."
android:textColor="#FFFFFFFF"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:background="@drawable/download1"/>

</androidx.cardview.widget.CardView>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@color/purple_500"
android:foregroundGravity="bottom"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cv2"
app:layout_constraintVertical_bias="1.0"
android:id="@+id/navigation"
Divyesh Patel 19012011111
Practical: 6
app:menu="@menu/navigation_bar">

</com.google.android.material.bottomnavigation.BottomNavigationView>

</androidx.constraintlayout.widget.ConstraintLayout>

Strings.xml
<resources>
<string name="app_name">19012011111_Divyesh Patel</string>
</resources>

Output:

Divyesh Patel 19012011111

You might also like