Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday 3 December 2015

"Failed to create jvm, error code - 4" Android Studio

Hi Friends,

If you are facing this problem
failed to create jvm error code -4 JVM Path: C:\Program Files\Java\jdk1.7.0_45\jre If you already have a 32-bit JDK installed, define a JAVA_HOME variable in Which is not solved.

Then here is the solution:

Go to C:\Program Files\Android\Android Studio\bin\studio.exe.vmoptions

or open the path where you have installed your Android Studio and open the "studio.exe.vmoptions" file in Notepad or Notepad++.




Open it in Notepad or Notepad ++ and change the following attributes

-Xmx512m to -Xmx256m

-XX:MaxPermSize=250m to -XX:MaxPermSize=128m

OR

-Xmx750m to -Xmx512m

-XX:MaxPermSize=350m to -XX:MaxPermSize=250m
Read more...

Thursday 26 November 2015

Cannot resolve symbol HttpGet,HttpClient,HttpResponce in Android Studio

Today I was facing this issue "Cannot resolve symbol DefaultHttpClient" while parsing JSON in my application.

So Friends!! if you are also facing or will face the same issue then I'm giving you the solution for it. HttpClient was deprecated in API Level 22 and removed in API Level 23, You have to use URL Conntection. If you need SDK 23, add this to your gradle:

android {
    useLibrary 'org.apache.http.legacy'
}

Please remove all jar files of Http from libs folder and add below dependencies in gradle file:

compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'org.apache.httpcomponents:httpcore:4.4.3'


Read more...

Friday 30 October 2015

Gradle Sync problem - failed to sync Gradle project

Hello guys!!

You may face this sync Gradle project when upgrade the Android Studio or low heap size like this





So here is the solution for it.

For Android Studio 1.3 : (Method 1)
Step 1 : Open gradle.properties file in your Android Studio project.
Step 2 : Add this line at the end of the file
org.gradle.jvmargs=-XX:MaxHeapSize\=256m -Xmx256m Above methods seems to work but if in case it won't then do this (Method 2)
Step 1 : Start Android studio and close any open project (File > Close Project).
Step 2 : On Welcome window, Go to Configure > Settings.
Step 3 : Go to Build, Execution, Deployment > Compiler
Step 4 : Change Build process heap size (Mbytes) to 1024 and Additional build process to VM Options to -Xmx512m.
Step 5 : Close or Restart Android Studio.
Read more...

Monday 26 October 2015

Display HTML format text in WebView

I have faced this problem to show the HTML format text show in WebView
I found the solution for this and lets share it -

Create a xml with WebView
<LinearLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</LinearLayout>

Now create the Activity
package com.example.androidhtmltextsample;

import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;

public class MainActivity extends Activity {

 WebView webView;
 
 String mimeType = "text/html";
 String encoding = "utf-8";
 String htmlText = "<ul>\n<li>Apple cider vinegar dries acne without causing any apparent discomfort.</li>" +
        "\n<li>Another interesting acne overnight treatment is the application of toothpaste.</li>" +
        "\n<li>Follow this up by applying a bit of alcohol over the affected area just prior to bedtime.</li>" +
        "\n<li>Do not apply gel based toothpastes on the affected areas.</li>\n</ul>";
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  webView = (WebView)findViewById(R.id.webview);
  webView.loadData(htmlText, mimeType, encoding);
 }

}




Now add the Internet Permission in Menifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"    
package="com.example.androidhtmltextsample"    
android:versionCode="1"    
android:versionName="1.0" >

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

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

    <application android:allowBackup="true"        
                 android:icon="@drawable/ic_launcher"        
                 android:label="@string/app_name"       
                 android:theme="@style/AppTheme" >
        <activity android:name="com.example.androidhtmltextsample.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>

Read more...

Thursday 15 October 2015

Can we use strikethrough on sticky notes

The "Sticky Notes" that come with Windows7 happens to be a very good application. With this you can keep a track of your task list by scribbling stuff on it.

Well, since the font formating capabilities of these notes was not very impressive I was just wondering if there is an alternative to strikethrough/strikeout a scribbled line from the note... and guess what! It does have a shortcut... Just like Ctrl+b is for Bold and Ctrl+i is for itallic, Ctrl+t is for Strikethrough/Strikeout.
Read more...

Thursday 8 October 2015

Android Button: Place Image and text in center

Hello Guys!!

If you are facing issue to place image and text at center of any button then please refer my blog -


<?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="wrap_content"
    android:orientation="vertical">



<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <TableRow
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:weightSum="4">
                    <RelativeLayout
                        android:id="@+id/layout_Views"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/blue">
                        <TextView
                            android:id="@+id/txt_viewCount"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:gravity="center"
                            android:padding="9dp"
                            android:text="214 Views"
                            android:textColor="#fff" />
                    </RelativeLayout>
                    <RelativeLayout
                        android:id="@+id/layout_Votes"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/red">
                        <TextView
                            android:id="@+id/txt_Votes"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:gravity="center"
                            android:padding="9dp"
                            android:text="214 Views"
                            android:textColor="#fff" />
                    </RelativeLayout>
                    <RelativeLayout
                        android:id="@+id/layout_share"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/green">
                        <ImageView
                            android:id="@+id/img_share"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/ic_share" />
                    </RelativeLayout>
                    <RelativeLayout
                        android:id="@+id/layout_bookmark"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@color/yellow">
                        <ImageView
                            android:id="@+id/img_boomark"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/ic_bookmark" />
                    </RelativeLayout>
                </TableRow>
            </TableLayout>
        </LinearLayout>

</LinearLayout>


Output is -

Read more...

Wednesday 30 September 2015

How to write multi-line in EditText view

Hey guys,

I have facing problem while creating an EditText view which support multi-lines as on some application it required on creating some Form which need it.

So here I am giving you the sample code to solve this problem and save your time.

By default all the EditText widgets in Android are multi-lined.
<EditText
    android:inputType="textMultiLine" <!-- Multiline input -->
    android:lines="8" <!-- Total Lines prior display -->
    android:minLines="6" <!-- Minimum lines -->
    android:gravity="top|left" <!-- Cursor Position -->
    android:maxLines="10" <!-- Maximum Lines -->
    android:layout_height="wrap_content" <!-- Height determined by content -->
    android:layout_width="fill_parent" <!-- Fill entire width -->
    android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
/>

Read more...

Create Custom Spinner with background shape

Hello Guys,

If you are looking for creating Custom Spinner like this
enter image description here

Then I am here to help you :-)
Create an XML in drawable folder with any name for example spinner_bg.xml and add the following lines
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape>
                    <stroke android:width="3dp" android:color="#ebebeb" />

                    <corners android:radius="5dp" />

                    <solid android:color="#fff"></solid>
                </shape>
            </item>
            <item>
                <bitmap android:gravity="bottom|right" android:src="@drawable/ic_arrow_drop_down" />
            </item>
        </layer-list>
    </item>
</selector>
Add the following lines to your styles.xml which is inside values folder
<style name="spinner_style" >
    <item name="android:background">@drawable/spinner</item>
    <item name="android:popupBackground">#DFFFFFFF</item>
</style>
Now add this style to your spinner as

<Spinner
    android:id="@+id/condition"
    style="@style/spinner_style"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="15dp"
    android:popupBackground="#cccccc" />




Read more...

Saturday 12 September 2015

Set the Genymotion Android Emulator in Windows

What is Genymotion ?

Genymotion is the fastest Android emulator for app testing. Genymotion is the evolution of AndroidVM open source project, already trusted by 300 000 developers. Here I am using 64 bit Windows 8 for using Genymotion. Here we are going to setup Android 4.2.2 on a Windows operating system using Genymotion.

 

Features of Genymotion:

1.Fastest Android emulator on the planet.
2.Do your simultanous automatic tests on unlimited virtual appliances .
3.Directly launch Genymotion from your Eclipse and Android Studio platforms.
4.It has Open GL acceleration ,multiscreen and full screen display.

 

Configure Genymotion with Android Studio:

1.Download genymotion-idea-plugin-20130716.jar plugin from the link http://plugins.genymotion.com/plugins/idea/1.0.1/genymotion-idea-plugin-20130716.jar
2.Open Android Studio IDE
3.Open File->Settings and the IDE Settings->Plugins
4.Choose Install plugin from disk and choose the downloaded genymotion-idea-plugin-20130716.jar
5.Now Apply Changes
6.In Android Studio select Run->Edit configurations
7.Select Target device as Show chooser dialog.
8.Now you can test your Application in Genymotion by choosing Genymotion from the Choose Device dialog while running your Application.
Read more...

Thursday 10 September 2015

android: How to make the button transparent and have background color

Using XML
If you want to set color and along with that if you want to set transparent then you have to use that color code .

android:color="#66FF0000"    // Partially transparent red
android:alpha="0.25"         // 25% transparent 

Using java
And if you want to set dynamically (java code)then try this,

myButton.getBackground().setAlpha(64);  // 25% transparent

- i.e .INT ranges from 0 (fully transparent) to 255 (fully opaque)


Reference- http://stackoverflow.com/questions/20743124/setting-transparency-to-buttons-in-android
Read more...

Friday 10 July 2015

Create Wordpress Website on a localhost using XAMPP

Hi Friends,

I believe this blog help you make it very simple to create your own website on Wordpress.
So without wasting much time lets start creating it,

1. Firstly download XAMPP.

    XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is           really very easy to install and to use - just download, extract and start.
    http://www.apachefriends.org/en/xampp

   
2. After completion of XAMPP download lets run the "XAMPP Control Panel"
    Start 'Apache' & 'MySQL'

3. Now download Wordpress from http://wordpress.org/download/

4. Extract the zip folder of wordpress in C:\xampp\htdocs\wordpress location

5. Click on the admin button on 'MySQL' from XAMPP control panel which opens http://localhost/phpmyadmin/

6. Create a new database by selecting new on left menu drawer and named it 'wordpress'

7. Now go to wordpress folder located in htdocs (C:\xampp\htdocs\wordpress) and open in Notepad/Notepad++ and change the database name default to 'wordpress' as shown below:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

and save as "wp-config.txt" in the same folder (C:\xampp\htdocs\wordpress)

8. Now go to webpage and open http://localhost/wordpress and select 'Create configure file'
and configure the wordpress page as mentioned below:

Database username - wordpress
User Name - root (default username for MySQL)
Password -  (can left blank)
Database Host - (left as it is)
Table Prefix - (left as it is)

9. Now select "Run the install" and you can see the Welcome page of Wordpress. Now you can create worpress page as you want (eg. shown below:)

Set Title - Test
Username - (enter whatever you need)
Password -
Confirm Password -
Your Email -

Make sure the Privacy should be checked.

And select 'Install WordPress'.
Now you can start with WordPress login details.

Thats it!

Now you can see your WordPress website by selecting test - View site from top menu bar.


Congratulations!!
You have created your own website. Enjoy!!!

Thanks




Read more...

Friday 1 May 2015

Shake Animation Example

1.) Create a new project by File-> New -> Android Project name it ShakeAnimationExample.
2.) You will see some default code into your main.xml, strings.xml and android manifest file.
3.) Write following into main.xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dip"
        android:text="Please enter your password:"
    />
    
    <EditText android:id="@+id/pw"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:singleLine="true"
        android:password="true"
    />

    <Button android:id="@+id/login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"
    />

</LinearLayout>
4.) Create and Write following into anim/shake.xml:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
 android:interpolator="@anim/cycle_7" />
5.) Create and Write following into anim/cycle_7.xml:
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
Steps:
1.) Create a project named ShakeAnimationExample and set the information as stated in the image.
2.) Open ShakeAnimationExample.java file and write following code there:
package com.example.ShakeAnimation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

public class ShakeAnimation extends Activity implements View.OnClickListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        View loginButton = findViewById(R.id.login);
        loginButton.setOnClickListener(this);
    }

    public void onClick(View v) {
        Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
        findViewById(R.id.pw).startAnimation(shake);
        Toast.makeText(this, "Wrong Password", Toast.LENGTH_SHORT).show();
    }

}       
3.) Compile and build the project.
4.) Run on simulator or phone for the output.
Read more...

Thursday 16 April 2015

Android character by character display text animation

This may not be the most elegant solution, but the simplest is probably a quick subclass of TextView with a Handler that updates the text every so often until the complete sequence is displayed:
 
public class Typewriter extends TextView {

    private CharSequence mText;
    private int mIndex;
    private long mDelay = 500; //Default 500ms delay


    public Typewriter(Context context) {
        super(context);
    }

    public Typewriter(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private Handler mHandler = new Handler();
    private Runnable characterAdder = new Runnable() {
        @Override
        public void run() {
            setText(mText.subSequence(0, mIndex++));
            if(mIndex <= mText.length()) {
                mHandler.postDelayed(characterAdder, mDelay);
            }
        }
    };

    public void animateText(CharSequence text) {
        mText = text;
        mIndex = 0;

        setText("");
        mHandler.removeCallbacks(characterAdder);
        mHandler.postDelayed(characterAdder, mDelay);
    }

    public void setCharacterDelay(long millis) {
        mDelay = millis;
    }
}
You can then use this in an Activity like so:


public class MyActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Typewriter writer = new Typewriter(this);
        setContentView(writer);

        //Add a character every 150ms
        writer.setCharacterDelay(150);
        writer.animateText("Sample String");
    }
}
  
If you want some animation effects with each letter added, perhaps look at subclassing TextSwitcher instead.
Hope that Helps!

There are many ways to show the characters using "string.xml".
/* One method to get the characters from String*/
writer.animateText(getString(R.string.poem_one)); //get the text from string.xml
       
/* One more method to retrieve the character from String*/
CharSequence  cs = getText(R.string.poem_one);
writer.animateText(cs);
Read more...

Wednesday 15 April 2015

How to create Ticker (marquee text)

If you want marquee text in your application, here is the simplest example.
In your xml-layout file, add this to your TextView
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
and in your code to start animation:
TextView tv = (TextView) findViewById(R.id.tv);
tv.setSelected(true);
 
Via the API:
 
Read more...

Sunday 1 March 2015

How to set string array from string.xml in listview

If you want the values of string array to listview.
private String [] fiilliste={"A","AÄŸlamak","Almak","B","Bulmak"};
ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, fiilliste);
vlist.setAdapter(adapter);
And wanna use xml file for string-array. 
<?xml version="1.0" encoding="utf-8"?>
<resources>

     <string-array name="fi">
        <item>A</item>
        <item>Almak</item>
        <item>Anlamak</item>
        <item>Anlasmak</item>
        <item>Anlatmak</item>
        <item>Ayrilmak</item>
    </string-array>

</resources>
So you just have to do like this:
String [] fiilliste;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.verbs);
    fiilliste = getResources().getStringArray(R.array.fi); 
    // move this in onCreate
Read more...

Wednesday 18 February 2015

Open any Website into Android Application

If you want to open any website in your custom view of Android application,
Here are the few steps to get it.

1. Create a new Project
2. Modify the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="MergeRootFrame">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </WebView>
   
</FrameLayout>
3. Now open the MainActivity.java class
package com.example.webviewdemo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity{
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView)findViewById(R.id.webview);

        // Enable Javascript
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.loadUrl("http://www.fashionandyou.com/");

        // Stop local links and redirects from opening in browser instead of WebView
        webView.setWebViewClient(new MyWebViewClient());
    }

    @Override
    public void onBackPressed() {
        if (webView.canGoBack()){
            webView.goBack();
        }else {
            super.onBackPressed();
        }
    }
}
4. Now create a new class MyWebViewClient.java
package com.example.webviewdemo;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MyWebViewClient extends WebViewClient{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(Uri.parse(url).getHost().endsWith("fashionandyou.com")){
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}
5. Now add the INTERNET permission in AndroidMenifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>
Read more...

Monday 9 February 2015

Show Hindi font (custom font) text in Android

In your custom apps you will most probably want to use your own font. This post will show you how you can do so. This is a simple example... create a folder in the root of your project called assets/fonts/ then paste the TTF font file (in this case Devanagri.TTF). Then, if you want to apply that font to, say a TextView, do the following
TextView tv = (TextView ) findViewById(R.id.textView);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/hindi.ttf");
tv.setTypeface(face);
tv.setText("Hindi font");
Read more...

Friday 6 February 2015

Remove line in between two listView (or single listView)

There are different ways to achieve this, at least 2 different ways to do this in a ListView:

1. Set divider to null:
1.1. Programmatically
yourListView.setDivider(null);
1.2. XML
android:divider="@null" (this goes inside your ListView element)
2. Set divider to transparent and set its height to 0 to avoid adding space between listview elements:
2.1. Programmatically:
yourListView.setDivider(new ColorDrawable(android.R.color.transparent));
yourListView.setDividerHeight(0);
2.2. XML
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
 
developer.android.com: #ListView 
Read more...

Friday 30 January 2015

Rotate Animation sample using XML in Android

I would like to share this example of Rotation Animation as this may be very helpful to the needy one.

In this example, I’ll try to introduce you doing simple animations with Android. It is simple enough that on clicking a button, an images starts rotating from 0 degree to 360 degree in N seconds. Lets begin with the animation XML. Once you have created a new Android project, create a folder named "anim" in res and a file named 'rotator.xml' inside res/anim. 

res/anim/rotator.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
  <rotate
      android:fromDegrees="0"
      android:toDegrees="360"
      android:pivotX="50%"
      android:pivotY="50%"
      android:duration="2000"
      android:startOffset="0"/>
</set>

Then open res/main.xml, after removing the default textView in the layout, add an ImageView and Button into the layout. Set the src property of the ImageView as your filename of the added image, for example android:src="@drawable/myimg" 

res/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:orientation="vertical" >
    <ImageView
        android:id="@+id/img_View"
        android:layout_width="
wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/myimg" />
    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"  />
</RelativeLayout>


OK, lets edit the main class. In the onClick() for the button, add the necessary code for running the animation. Check the following code. 

MainActivity.java
package com.example.ImageRotation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn = (Button) findViewById(R.id.btn);
      
        btn.setOnClickListener(new OnClickListener()    {
            @Override
            public void onClick(View arg0) {
                final ImageView myImage = (ImageView)findViewById(R.id.img_View);
                final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator);
                myImage.startAnimation(myRotation);
            }
        });

    }
}



 
Read more...