Search Wikipedia

Search results

Oct 18, 2013

Content menu in Android

  Creating a Content Menu


Android has a unique mechanism called long press.
 When we click any button or image for long time a kind of menu appears that is called content menu.

Today i am doing a project related to this.
First of all i create a project called "Content_menu".
Then go to XML file.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

activity_main.xml


<RelativeLayout 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"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="106dp"
        android:layout_marginTop="159dp"
        android:text="@string/button" />
</RelativeLayout>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Adding a button in xml

Then i create a new xml file called contentmenu.xml
Note: Choose menu in Resource Type

Creating a new XML file

Option Menu in Android

Creating an option menu


There are different kinds of menu in android.
Today i am gonna  create a option menu.
There are couple of ways of creating option menu.
One  is directly by java code and another is using XML.

But in my case i will use XML because it provides good graphical interface and its easy to handle in compare to java. So i create a new XML file.

Creating a mymenu.xml


mymenu.xml


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

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item android:id="@+id/item1" 
        android:title="Option 1" 
        android:icon="@android:drawable/ic_menu_compass"/>
   
    <item android:id="@+id/item2 "
        android:title="Option 2" 
        android:icon="@android:drawable/ic_menu_call"/>
</menu>


mymenu.xml



Oct 17, 2013

Drawing animation in Android

Drawing graphics directly using XML

We can also draw graphics in android using XML .
First i need to create a blank project called "Drawing"
Then make a new  file inside the drawable folder called rect.xml.

Creating a new xml file 
I write this codes inside my rect.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>
    <padding
        android:left="7dp"
        android:right="7dp"
        android:top="7dp"
        android:bottom="7dp"/>
    <corners android:radius="10dp"/>
    </shape>

Animation.xml


Tween animation in Android

Using Tween animation


After frambyframe animation lets focus on tween animation, it is much simpler to program essentially we give start and end values to android and it gonna interpolate the values between them itself.
First of all i make a blank project called Tween.
Change the layout to relative but mine is relative layout by default.
Now i drag a button in the layout.

Dragging button in my layout


Oct 16, 2013

FramebyFrame Animation in Android

Using framebyframe technique for animation in android


Today i will use frame by frame way of animation . Here i have a sequence of images which  will be use as frames and continuous rapid  change in these  frames cause the illusion which looks like an animation.

OK lets then start.
I create a new project called "Anime".
I got a collection of images which contains 33 images. You can also make such images using Photoshop or any other photo-editor applications.

My image collection which will be use for Frame animation

 Now i come to my resource directory in eclispe i.e. res folder.And i drag all my images in drawable folder.

Dragging images in drawable folder

Now i go to my XML file and change my layout from Linear Layout to Relative Layout.
 Here i need a imageview so i drag a imageview in my layout.
Dragging imageview in my layout


Alternate layout and Resources

 Creating an Alternate Layout and Resources


Android provides an alternate layouts and resources based upon the devices used.
If we develop any apps in portrait form then it may not look good in landscape mood.
Here i am gonna develop an alternate layout for landscape mood.
Then lets start.
 I create a new project named "Alternate"
Then i go to XML file and drag a button, a textview, togglebutton and a imageview.

Here is portrait view
Layout in Protrait View
When i switch this layout to landscape it looks like this and it is not good.

Layout view in Landscape mode


Using Explicit intent

Sending data from one Activity to another Activity


Today i am using explicit intents to send data from one activity to another . For this i create a new project called Explicit. Then i create new XML file in layout called Second.xml.
As i am sending data from one to another activity . I need to create a new activity for this i go to src and right click it and create new java file(activity)

Creating new java class for new activity

After creating, open second.java and a blank class appears . I need to extend that class by Activity.After extending, i need to right click in between two curly braces then go to Source and then click Override/Implement Methods.



}