0% found this document useful (0 votes)
4 views26 pages

More

The document contains multiple practical exercises by Shraddha Pandit Hivare, focusing on Android XML layout files and Java code for creating user interfaces. It includes various layout types such as ConstraintLayout, LinearLayout, TableLayout, AbsoluteLayout, FrameLayout, and RelativeLayout, each demonstrating different UI components like TextViews, EditTexts, and Buttons. The document serves as a practical guide for developing Android applications with different layout structures.

Uploaded by

Priti Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

More

The document contains multiple practical exercises by Shraddha Pandit Hivare, focusing on Android XML layout files and Java code for creating user interfaces. It includes various layout types such as ConstraintLayout, LinearLayout, TableLayout, AbsoluteLayout, FrameLayout, and RelativeLayout, each demonstrating different UI components like TextViews, EditTexts, and Buttons. The document serves as a practical guide for developing Android applications with different layout structures.

Uploaded by

Priti Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Practical No:- 2

Name: Shraddha Pandit Hivare Roll No: 24/36-16


Practical No:- 3
Name: Shraddha Pandit Hivare Roll No: 24/36-16
Practical No:- 4
Name: Shraddha Pandit Hivare Roll No: 24/36-16
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Output:
Practical No:- 5
Name: Shraddha Pandit Hivare Roll No: 24/36-16

Program:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView android:id="@+id/nameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="8dp" />

<EditText android:id="@+id/nameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prathmesh Raje"
android:layout_marginBottom="16dp" />

<TextView android:id="@+id/ageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="8dp" />

<EditText
android:id="@+id/ageInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="05"
android:inputType="number"
android:layout_marginBottom="16dp" />
<TextView android:id="@+id/phoneLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile Number"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="8dp" />

<EditText android:id="@+id/phoneInput"
android:layout_width="match_pa
rent"
android:layout_height="wrap_co ntent"
android:text="********42"
android:inputType="phone"
android:layout_marginBottom="16dp" />

</LinearLayout>

MainActivity.java
package com.example.myapplication;

import android.os.Bundle;

import androidx.activity.EdgeToEdge; import


androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets; import
androidx.core.view.ViewCompat; import
androidx.core.view.WindowInsetsCom
pat;

public class MainActivity extends AppCompatActivity {


@Override protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.nameLabel), (v,
insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
}
}

Output: -
Absolute Layout
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t1"
android:text="krishana"
android:textSize="40sp"
android:textColor="#00f"
android:layout_x="100sp"
android:layout_y="300dp"
</AbsoluteLayout>
Output:
Practical No:- 6
Name: Shraddha Pandit Hivare Roll No: 24/36-16

Table Layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<TableRow android:layout_width="100dp"
android:layout_height="100dp">

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0" android:text="
Weather Information" android:layout_span="8"
android:textColor="#8C0000" android:textSize="16sp" />
</TableRow> <TableRow
android:layout_width="900dp"
android:layout_height="90dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Date "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="20Jan "
android:textColor="#8C0000"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="21Jan "
android:textColor="#8C0000"
android:textSize="16sp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="22Jan "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:text="23Jan "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="5"
android:text="24Jan "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="6"
android:text="25Jan "
android:textColor="#8C0000"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="7"
android:text="26Jan "
android:textColor="#8C0000"
android:textSize="16sp" />
</TableRow>

<TableRow
android:layout_width="100dp"
android:layout_height="100dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Day "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="Mon "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="Tue "
android:textColor="#8C0000"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Wed "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:text="Thu "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="5"
android:text="Fri "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="6"
android:text="Sat "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="7"
android:text="Sun "
android:textColor="#8C0000"
android:textSize="16sp" />
</TableRow>

<TableRow android:layout_width="100dp"
android:layout_height="100dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Temp "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="155dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_span="3" android:text="
45 C" android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:text="30 C "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="5"
android:text="29 C "
android:textColor="#8C0000"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="6"
android:text="25 C "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="7"
android:text="33 C "
android:textColor="#8C0000"
android:textSize="16sp" />
</TableRow>

<TableRow android:layout_width="100dp"
android:layout_height="100dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Desc "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text=" High "
android:layout_span="2"
android:textColor="#8C0000"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Extreme "
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:text="Cloudy"
android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="5"
android:layout_span="2" android:text="
Cold " android:textColor="#8C0000"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="7"
android:text="Rainy "
android:textColor="#8C0000"
android:textSize="16sp" /> </TableRow>
<TableRow
android:layout_width="100dp"
android:layout_height="100dp">
<TextView
android:layout_width="wrap_content
"
android:layout_height="wrap_content
" android:layout_column="0"
android:text="Image "
android:textColor="#8C0000"
android:textSize="16sp" />

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_column="1"
android:id="@+id/i1"
android:src="@drawable/high"
android:layout_span="2” />

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_column="3"
android:id="@+id/i2"
android:src="@drawable/extreame"
/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_column="4"
android:id="@+id/i3"
android:src="@drawable/cloudy"
/>
<ImageView android:id="@+id/i4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_column="5"
android:layout_span="2"
android:src="@drawable/cold"
/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_column="7"
android:id="@+id/i5"
android:src="@drawable/rainy"
/>
</TableRow>
</TableLayout>
Output:
Frame Layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:scaleType="fitCenter"
android:src="@drawable/flower"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="vpp"
android:textSize="30sp"
android:gravity="center"/>
</FrameLayout>
Output:
Practical No:- 7
Name: Shraddha Pandit Hivare Roll No: 24/36-16

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp">

<TextView android:id="@+id/usernameLabel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Username" android:textSize="16sp"
android:layout_marginTop="50dp" /> <EditText android:id="@+id/username"
android:layout_width="match_parent" android:layout_height="48dp"
android:layout_below="@id/usernameLabel" android:layout_marginTop="10dp"
android:hint="Enter your username" android:inputType="textPersonName" />

<TextView android:id="@+id/passwordLabel"
android:layout_width="wrap_content" android:layout_height="48dp"
android:text="Password" android:textSize="16sp"
android:layout_below="@id/username" android:layout_marginTop="20dp" />

<EditText android:id="@+id/password" android:layout_width="match_parent"


android:layout_height="48dp" android:layout_below="@id/passwordLabel"
android:layout_marginTop="10dp" android:hint="Enter your password"
android:inputType="textPassword" />

<Button android:id="@+id/loginButton" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:text="Login"
android:layout_below="@id/password" android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" />
</RelativeLayout>

MainActivity.java:
package com.example.textviewandedittext; import android.os.Bundle; import
android.view.View; import android.widget.Button; import android.widget.EditText; import
android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class
MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle
savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); EditText username =
findViewById(R.id.username);
EditText password = findViewById(R.id.password);
Button loginButton = findViewById(R.id.loginButton);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
String usernameInput = username.getText().toString();
String passwordInput = password.getText().toString();

// You can add validation logic here


Toast.makeText(MainActivity.this, "Username: " + usernameInput + "\nPassword: "
+ passwordInput, Toast.LENGTH_LONG).show();
}
});
}
}
Output:
Practical No:- 8
Name: Shraddha Pandit Hivare Roll No: 24/36-16

AutoImageSlider:
MainActivity.java:
package com.example.autoimage;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


AutoCompleteTextView a1;
String[] city = {"Indapur", "Indore", "Baramati", "Pune", "Singapore"};

@Override protected void onCreate(Bundle savedInstanceState)


{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
show();
}
public void show() { a1 =
findViewById(R.id.auto);
ArrayAdapter<String> adp = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, city); a1.setThreshold(1);
a1.setAdapter(adp);
}
} activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<AutoCompleteTextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/auto"
android:layout_marginTop="30dp" android:ems="10"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

Output:

You might also like