Android AbsoluteLayout
Android AbsoluteLayout
Static AbsoluteLayout Creation in Android.
Dynamic AbsoluteLayout Creation in Android.
Static AbsoluteLayout Creation in Android.
Step 1 : Select
File -> New -> Project -> Android Application Project (or)
Android Project. Fill the forms and click "Finish" button. If you have
any doubt regarding create a new project Click Here.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<AbsoluteLayout 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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"
android:textColor="#4B0082"
android:layout_x="80dp"
android:layout_y="55dp"
android:text="AbsoluteLayout" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:layout_x="114dp"
android:layout_y="193dp"
android:text="Button" />
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:layout_x="38dp"
android:layout_y="322dp"
android:text="ToggleButton 1" />
<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:layout_x="200dp"
android:layout_y="320dp"
android:text="ToggleButton 2" />
</AbsoluteLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package com.gudivada.hemanthsomaraju;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ToggleButton tg1 = (ToggleButton) findViewById(R.id.toggleButton1);
final ToggleButton tg2 = (ToggleButton) findViewById(R.id.toggleButton2);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(tg1.isChecked())
Toast.makeText(getBaseContext(), "Toggle Button 1" +
"\n \n \t is Checked", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getBaseContext(), "Toggle Button 1" +
"\n \n is not Checked", Toast.LENGTH_SHORT).show();
}
});
b.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
if(tg2.isChecked())
Toast.makeText(getBaseContext(), "Toggle Button 2" +
"\n \n \t is Checked", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getBaseContext(), "Toggle Button 2" +
"\n \n is not Checked", Toast.LENGTH_SHORT).show();
return true;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Step 4 : Open AndroidManifest.xml and add following code :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gudivada.hemanthsomaraju"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.gudivada.hemanthsomaraju.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 5 : Our output will be like this :
Dynamic AbsoluteLayout Creation in Android.
Step 1 : Select
File -> New -> Project -> Android Application Project (or)
Android Project. Fill the forms and click "Finish" button. If you have
any doubt regarding create a new project Click Here.