Sunday 29 December 2013

Android APK (File format)


Android Application Package APK (.apk) is the set of compressed files used to distribute and install application software on well know Android Operating system by Google Inc.

Android apk contains the number of files that all contains program's code, assets, resources, permissions, certification and manifest file.

You can also check the contents of apk file by just following these steps.

  1. Rename .apk extension to .rar
  2. Extract these files with help of decompression tools such as Winrar or Winzip
Usually apk file contains the following file 

Android apk file format

  • lib
  • res
  • assets
  • classes.dex
  • AndroidManifest.xml
  • META-INF directory
  • resources.arsc

lib

It contains the compiled code that is specific to a software layer of a processor, the directory is split into more directories within it.
  • armeabi: compiled code for all ARM based processors only
  • armeabi-v7a: compiled code for all ARMv7 and above based processors only
  • x86: compiled code for x86 processors only
  • mips: compiled code for MIPS processors only

res

Contains the resources file such as layout, images and few xml files, which are not compiled into resources.arsc


Assets

It contains assets files specific to a particular project, which can be retrieved with use of Assets Manager, these files have been integrated to a project by the user. 



Classes.dex

It contains the compiled classes in the dex format, which is being understandable by Dalvik Virtual Machine


AndroidManifest.xml

 An additional Android manifest file, describing the name, version, access rights, referenced library files for the application. 


META-INF directory

Its java's internal meta directory contains the following files 
  • MANIFEST.MF: the Manifest file
  • CERT.RSA: The certificate of the application.
  • CERT.SF: The list of resources and SHA-1 digest of the corresponding lines in the MANIFEST.MF file

resources.arsc

Contains the pre compiled resources file such as layout, images and few xml files




Thursday 26 December 2013

Different ways to Install apk.

There are different ways to install apk other than market, here are few check it out.


  1.  Using USB 

  • Connect USB to your PC
  • If you device OS version is greater than 2.3 then 
    • Settings
    • Developer Option
    • Check Install from Unknown resource
  • If you device OS version is 2.3 or less 
    • Settings
    • Applications
    • Check Unknown resource
  • Copy apk file into your SD card or Phone Internal Memory
  • Locate the apk file & click on it. 
  • Select package installer 


    2. Using AirDroid



  • Select App as shown in red box for below image and also drag and drop apk into the green box shown. 

  •  Mission Accomplished 



      3. Using Command Line






Happy Installing....
Feel free to add any other mothod.

Thursday 12 December 2013

Android Native Data to HTML page

Here comes one more Blog on HTML5.

Have you ever tried sending data from Android native to HTML page? like SMS, Call, JSON Array etc.

This blog gives you a clear picture how to pass Data to HTML5.

I have created 2 methods getTimeAndroid() which passes String to setTime() (javascript method)and getValueJson() passes JsonArray to setJson() (javascript method) respectively.

You need a "JavascriptInterface" which is a class written by you in your activity, a HTML page where you define methods & pass arguments to Android java class.






Android Native code 



package com.rnd.rnd;

import java.text.SimpleDateFormat;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

public class HtmlToAndroid extends Activity{
WebView mWebview;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.html_layout);
// Assing webview object
mWebview = (WebView)findViewById(R.id.webview);
// Load your html page here
// Enable javascript 
mWebview.getSettings().setJavaScriptEnabled(true);
// Adding javascript interface to your page. 
// Pass the JavaScriptInterface class & related String "AndroidNativeCode" which will be used to call android methods written below. 
mWebview.addJavascriptInterface(new JavaScriptInterface(this), "AndroidNativeCode");
mWebview.loadUrl("file:///android_asset/www/index.html");
}
public class JavaScriptInterface {
        Context mContext;

     
        JavaScriptInterface(Context c) {
            mContext = c;
        }

        // Simple method to pass Data to HTML
        
     @SuppressLint("SimpleDateFormat")
@JavascriptInterface
        public void getTimeAndroid() {
     
    long date = System.currentTimeMillis(); 

SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm");
             mWebview.loadUrl("javascript:setTime('"+sdf.format(date)+"')");
     
        }
     
     // method to send JsonArray to HTML
     @JavascriptInterface
     public void getValueJson() throws JSONException
     {
    JSONArray jArray = new JSONArray();
      
     
      JSONObject jObject = new JSONObject();
      
      jObject.put("Name", "Jackson");
      jObject.put("Age","24");
      jArray.put(jObject);
      
      jObject = new JSONObject();
      jObject.put("Name", "Jenny");
      jObject.put("Age","23");
      jArray.put(jObject);
      
      jObject = new JSONObject();
      jObject.put("Name", "Fenny");
      jObject.put("Age","28");
      jArray.put(jObject);
      
      mWebview.loadUrl("javascript:setJson("+jArray+")");
          
      
     }
        
    }
}


HTML page

<html>
<head>
<title>Android is Awesome!!</title>

<script type="text/javascript">

function getTime()
{
AndroidNativeCode.getTimeAndroid();
}



function setTime(time)
{
document.getElementById('datetime').innerHTML = time;
}


function getJson()
{
AndroidNativeCode.getValueJson();
}

function setJson(Jsonobject)
{

var log="";
for(var i =0; i<Jsonobject.length;i++)
{
log+= Jsonobject[i].Name +" : "+ Jsonobject[i].Age + "<br> <br>" ;

}
document.getElementById('JsonDiv').innerHTML = log;
}
</script>

</head>

<body>
<br>
<h1>Android DATA to HTML</h1>
<br>
<Button onclick="getTime()">Time</Button>
<div id="datetime"></div>


<Button onclick="getJson()">JSon Data</Button>
<div id="JsonDiv"></div>

</div>


</body>
</html>



Android Layout


<?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" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

If you like it then please share it. Also if you know anything like please feel free to share

Also see 


  1. Also check out how to operate your Android phone from Window OS. 
  2. Android apk generation through command line 
  3. Android SQL browsing through Windows
  4. Access Android Native code from HTML
  5. ADB over Wifi 
  6. EditText to TextView conversion 
  7. SVN for Android Eclipse



Wednesday 4 December 2013

HTML to Android Code Access - android html


Acess Android native code from HTML, Its not that tough as you think to access native code of Android.
You just need a "JavascriptInterface" which is a class written by you in your activity, a HTML page where you define methods & pass arguments to Android java class.

I have created a sample Android java class to
1. Show a Toast Notification
2. Alert builder
3. Progress Dialog


1. Show a Toast Notification
From html you will call below method like this, where you will pass the message to your Toast Notification
AndroidNativeCode.showToast(message);



2. Alert builder
From html you will call below method like this, where you will pass the Title & Message for AlertBuilder

AndroidNativeCode.showAlertDialog(title,message);





3. Progress Dialog
From html you will call below method like this, where you will pass integer to ProgressDialog, which will be active for defined milliseconds by you.

AndroidNativeCode.showProgressDialog(parseInt(seconds));



Android java code is as follows

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;

public class HtmlToAndroid extends Activity{
WebView mWebview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.html_layout);

// Assing webview object
mWebview = (WebView)findViewById(R.id.webview);

// Load your html page here
mWebview.loadUrl("file:///android_asset/www/index.html");

// Enable javascript
mWebview.getSettings().setJavaScriptEnabled(true);

// Adding javascript interface to your page.
// Pass the JavaScriptInterface class & related String "AndroidNativeCode" which will be used to call android methods written below.
// ex  AndroidNativeCode.showToast("Your toast notification")
mWebview.addJavascriptInterface(new JavaScriptInterface(this), "AndroidNativeCode");


}

public class JavaScriptInterface {
        Context mContext;

   
        JavaScriptInterface(Context c) {
            mContext = c;
        }

        // Simple method to display Toast Notification
     @JavascriptInterface
        public void showToast(String toast) {
            Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
   
        }
   
     // Simple method to disply Alert Dialog
     @JavascriptInterface
        public void showAlertDialog(String title, String message)
        {
        Builder alert = new AlertDialog.Builder(mContext);
       
        alert.setTitle(title);
        alert.setMessage(message);
       
        alert.setPositiveButton("Cool",new  DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


}
});
       
        alert.show();
        }
   
   
     // Simple method to display Progress Dialog
     @JavascriptInterface
        public void showProgressDialog(int seconds)
        {
        final ProgressDialog l_progressDialog = new ProgressDialog(mContext);
       
        l_progressDialog.setMessage("HTML to Android code");
        l_progressDialog.setTitle("Wait for "+seconds+" miliseconds");
        l_progressDialog.setCanceledOnTouchOutside(false);
       
        l_progressDialog.show();
       
        Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
    public void run() {
   
    l_progressDialog.dismiss();
    }
    }, seconds);
       
        }
     
    }
}



Layout code is as follows

<?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" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>




HTML page which needs to be put in Android Project assets folder inside www folder. 

<html>
<head>
<title>Android is Awesome!!</title>

<script type="text/javascript">
function getAlert()
{
var title = document.getElementById('alert_title').value;
var message = document.getElementById('alert_message').value;
AndroidNativeCode.showAlertDialog(title,message);
}

function getToast()
{
var message = document.getElementById('toast_input').value;
AndroidNativeCode.showToast(message);
}

function getProgressDialog()
{
var seconds = document.getElementById('progress_input').value;
AndroidNativeCode.showProgressDialog(parseInt(seconds));
}

</script>

</head>

<body>
<br>
<center><h1>HTML to Android Native code access</h1></center>
<br><br>
<div>
Toast Message: <input type="text" id="toast_input"/>
<br>
<Button onclick="getToast()">Toast Message</Button>
</div>


<br><br>
<div>
Alert Dialog Title : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="alert_title"/>
<br>
Alert Dialog Message : <input type="text" id="alert_message"/>
<br>
<Button onclick="getAlert()">Get Alert</Button>
</div>


<br><br>
<div>
Progress Dialog Timing : <input type="number" id="progress_input"/>
<br>
<Button onclick="getProgressDialog()">Get Progress Dialog</Button>
</div>


</body>
</html>


Let me know if you have any doubts. 

Saturday 30 November 2013

Android SQLite browser without rooting the device

Its been many days I was finding difficult to check the data from DB present in phone internal memory. One solution was to pull 'mydatabase.sqlite' through the ADB but which requires a rooted device, one was to through Log.d(" ", " "); which is time consuming.

I have found one solution, just copy  'mydatabase.sqlite' database from your app (internal) to external memory.

Copy the same on your desktop and browse it with help Windows SQLite database browser

Copy the below code in your activity and pass the Source & Destination.

public void copy(File src, File dst) throws IOException {
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dst);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

Don't forget to give write external memory permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

Please share if you know any other method.

Also see 

  1. Also check out how to operate your Android phone from Window OS. 
  2. Android apk generation through command line 
  3. ADB over Wifi 
  4. EditText to TextView conversion 
  5. SVN for Android Eclipse


Monday 28 October 2013

Android ADB over wifi - Portable wifi device

Bored of connecting your Android device to ADB with traditional way wired/USB cable?
Here is the solution, connect your device to ADB over wifi & deploy your application for testing, how cool is that?
In order to make this successful you should 

There are two ways to connect,
1. Non-Rooted  Devices
2. Rooted Devices


For Non-Rooted Device

1. Connect your device to Computer


2. Once it is connected to ADB, 

Go to command prompt locate your Android sdk/platform-tools as shown below


3. Type the below command

adb tcpip 5555
adb connect 192.168.0.101:5555
Make sure you will replace your IP (Device IP) 

4. Remove USB cable 

Now your device is connected via wifi ADB. 

5. To revert back to USB

Just type 
adb usb



For Rooted-Device

1. Download apps

ADB wifi https://play.google.com/store/apps/details?id=com.ryosoftware.adbw&hl=enor Wifi ADB https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=enon your device. 

2. Go to command prompt

locate your Android sdk/platform-tools as shown below



3. open your any of the ADB wifi app 

now type in command adb connect 192.168.2.77 (as shown in your device)





4. Now you will be able to see 

connected to 192.168.2.77:5555



5. Now if you check you in DDMS you will be able to see your device connected in Device tab.


Enjoy ADB over wifi :) 
like it ? Please comment

Sliding Activities like Gallery ImageView

Have you ever tried of combining all 4 or more activities(layouts)  into single activity?
If not here is a sample which uses Image Gallery to load activities. 
I have used total 5 layouts (1 main & other 4 for 4 different activity) 
  • sliding_activity.xml
  • layout_1.xml
  • layout_2.xml
  • layout_3.xml
  • layout_4.xml
Also 5 classes (1 Main & 4 others)
  • SlidingActivity.java
  • layout_1.java
  • layout_2.java
  • layout_3.java
  • layout_4.java





















layout_1.java
Has a simple toast notifcation on click of a button



layout_2.java
Has a alert dialog to be opened on click of a button



layout_3.java
Has a image to be changed on click of a button 



layout_4.java
Has simple toast 



Java class code as follows

SlidingActivity.java

package com.rnd.slidingactivity;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.LinearLayout;

public class SlidingActivity extends Activity {
    /** Called when the activity is first created. */
Gallery my_gallery;
Integer[] integer_layouts= 
{
R.layout.layout_1,
R.layout.layout_2,
R.layout.layout_3,
R.layout.layout_4

};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.sliding_activity);
        
        my_gallery = (Gallery)findViewById(R.id.my_gallery);
        my_gallery.setAdapter(new LayoutAdapter());
    }
    
    public class LayoutAdapter extends BaseAdapter {
   
        
        
        public int getCount() {
             
            return integer_layouts.length;
        }

        public View getView(int arg0, View convertView, ViewGroup arg2) {

         LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         View layoutViews = (LinearLayout)inflater.inflate(integer_layouts[arg0], null, false);
        
         layoutViews.setLayoutParams(new Gallery.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)) ;
         
         if(arg0==0)
         {
          LayoutActivity1 la = new LayoutActivity1(SlidingActivity.this, layoutViews);
         }
         else if(arg0==1)
         {
          LayoutActivity2 la = new LayoutActivity2(SlidingActivity.this, layoutViews);
         }
         else if(arg0==2)
         {
          LayoutActivity3 la = new LayoutActivity3(SlidingActivity.this, layoutViews);
         }
         else if(arg0==3)
         {
          LayoutActivity4 la = new LayoutActivity4(SlidingActivity.this, layoutViews);
         }
           return layoutViews;
        }

        
        public Object getItem(int position) {
         // Do nothing
            return null;
        }

        
        public long getItemId(int position) {
         // Do nothing
            return position;
        }
    }
}


LayoutActivity1.java


package com.rnd.slidingactivity;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class LayoutActivity1 {
Context context;
View vw;
public LayoutActivity1(Activity act,View view)
{
context = act;
vw=view;

operations();
}

public void operations()
{
Button btn = (Button)vw.findViewById(R.id.btn_ll_1);

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
Toast.makeText(context, "You have clicked the second activity Control", Toast.LENGTH_LONG).show();

}
});
}

}


LayoutActivity2.java
package com.rnd.slidingactivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class LayoutActivity2 {
Context context;
View vw;
public LayoutActivity2(Activity act,View view)
{
context = act;
vw=view;

operations();
}

public void operations()
{
Button btn = (Button)vw.findViewById(R.id.btn_ll_2);

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

getAlert();

}
});
}

public void getAlert()
{
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Layout 2");
alert.setMessage("Alert for 2nd layout");

alert.setPositiveButton("Ok",new OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

}
});

alert.show();

}

}


LayoutActivity3.java
package com.rnd.slidingactivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class LayoutActivity3 {
Context context;
View vw;
public LayoutActivity3(Activity act,View view)
{
context = act;
vw=view;

operations();
}

public void operations()
{
Button btn = (Button)vw.findViewById(R.id.btn_ll_3);

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

changeImage();

}
});
}

public void changeImage()
{
ImageView img = (ImageView)vw.findViewById(R.id.img_ll_3);
img.setImageResource(R.drawable.droid);
}
}

LayoutActivity4.java
package com.rnd.slidingactivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class LayoutActivity4 {
Context context;
View vw;
public LayoutActivity4(Activity act,View view)
{
context = act;
vw=view;

operations();
}

public void operations()
{
Button btn = (Button)vw.findViewById(R.id.btn_ll_4);

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

Toast.makeText(context, "You are into Activity 4", Toast.LENGTH_LONG).show();

}
});
}


}


Layouts 
sliding_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Gallery
        android:id="@+id/my_gallery"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

layout_1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#222288" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="50dp" >


        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1st Layout"
            android:textSize="50dp"
            android:gravity="center"
            android:textColor="#ffffff"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <Button
        android:id="@+id/btn_ll_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Toast Notification" />

</LinearLayout>


layout_2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#228822" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="50dp" >


        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="2nd Layout"
            android:textSize="50dp"
            android:textColor="#ffffff"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <Button
        android:id="@+id/btn_ll_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Alert Dialog" />

</LinearLayout>

layout_3.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#881122" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="50dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="3rd Layout"
            android:textSize="50dp"
            android:textColor="#ffffff"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/img_ll_3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

    </LinearLayout>

    <Button
        android:id="@+id/btn_ll_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Change Image" />

</LinearLayout>

layout_4.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#311100" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="50dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="4th Layout"
            android:textSize="50dp"
            android:textColor="#ffffff"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceLarge" />

       
    </LinearLayout>

    <Button
        android:id="@+id/btn_ll_4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Toast Notification" />

</LinearLayout>

Manifest file 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rnd.slidingactivity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SlidingActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Now enjoy your sliding activity like gallery imageview