MCA Lab Manual New
MCA Lab Manual New
MCA Lab Manual New
Procedure:
Open Android Studio and Click on File -> New-> New Project
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
Now click on design mode and your android app design will look like below screen.
The design part for android application with text Hello World is done.
Result:
A simple android application to display Hello World message is developed and executed successfully.
Aim:
Procedure:
Open Android Studio and Click on File -> New-> New Project
<TextView
android:layout_marginTop="25dp"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:textColor="#3709F3"
android:textSize="30dp"
android:textStyle="bold"
android:text="Select Layout Type"/>
<Button
android:id="@+id/btnLinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Linear Layout"
android:layout_gravity="center"
android:layout_margin="15dp"/>
<Button
android:id="@+id/btnRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relative Layout"
android:layout_gravity="center"
android:layout_margin="15dp"/>
<Button
android:id="@+id/btnFrameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Frame Layout"
android:layout_gravity="center"
android:layout_margin="15dp"/>
</LinearLayout>
Switch to design view & verify the design for application interface.
Let’s add activity & design layout files for Linear Layout
Click on File -> New -> Activity -> Empty Activity
Enter Activity Name as LinearLayoutActivity
Enter Layout name as act_linear_layout
Click on Finish
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic|bold"
android:textSize="28dp"
android:textColor="#E00C0C"
android:text="Linear Layout"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second "
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Third"
/>
</LinearLayout>
Switch to design view & verify the design for application interface. Design will look like as below
screen.
Output:
When you change your code to android:orientation=" horizontal” screen will look below:
Let’s add activity & design layout files for Relative Layout.
Click on File -> New -> Activity -> Empty Activity
Switch to design view & verify the design for application interface. Design will look like as below screen.
Output:
Let’s add activity & design layout files for Frame Layout
Click on File -> New -> Activity -> Empty Activity
Enter Activity Name as FrameLayoutActivity
Enter Layout name as act_frame_layout
Click on Finish
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Frame Layout"
android:textSize="28dp"
android:textStyle="bold"
android:textColor="#FF0000"
android:gravity="center_horizontal"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="275dp"
android:layout_height="275dp"
android:src="@drawable/logo"
android:scaleType="fitCenter"
android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30dp"
android:textStyle="bold"
android:gravity="center"
android:text="Siddharth Institutions"/>
</FrameLayout>
</RelativeLayout>
Switch to design view & verify the design for application interface. Design will look like as below screen.
Button btnLinearLayout;
Button btnRelativeLayout;
Button btnFrameLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnLinearLayout=(Button)findViewById(R.id.btnLinearLayout);
btnLinearLayout.setOnClickListener(this);
btnRelativeLayout=(Button)findViewById(R.id.btnRelativeLayout);
btnRelativeLayout.setOnClickListener(this);
btnFrameLayout=(Button)findViewById(R.id.btnFrameLayout);
btnFrameLayout.setOnClickListener(this);
@Override
public void onClick(View view) {
if(view==btnLinearLayout)
{
Toast.makeText(getApplicationContext(),"Linear Layout Button is
Clicked",Toast.LENGTH_LONG).show();
Intent intentLinLayout=new
Intent(getApplicationContext(),LinearLayoutActivity.class);
startActivity(intentLinLayout);
}
else if(view==btnRelativeLayout)
{
Toast.makeText(getApplicationContext(),"Relative Layout Button is
Clicked",Toast.LENGTH_LONG).show();
Intent intentRelLayout=new
Intent(getApplicationContext(),RelativeLayoutActivity.class);
startActivity(intentRelLayout);
}
else if(view==btnFrameLayout)
{
Toast.makeText(getApplicationContext(),"Frame Layout Button is
Clicked",Toast.LENGTH_LONG).show();
Intent intentFrameLayout=new Intent(getApplicationContext(),
FrameLayoutActivity.class);
startActivity(intentFrameLayout);
}
}
}
Output: