Home
› Uncategorized
In this exercise, we are going to apply slide-in and slide-out animation on dialog, using windowAnimations.
Create/modify /res/values/styles.xml to add animation style of DialogAnimation, using build-in animation of slide_in_left and slide_out_right.
Implement our dialog layout, /res/layout/dialoglayout.xml.
MainActivity.java
Main layout:
Download the files.
Create/modify /res/values/styles.xml to add animation style of DialogAnimation, using build-in animation of slide_in_left and slide_out_right.
<resources> <style name="AppTheme" parent="android:Theme.Light" /> <style name="DialogAnimation"> <item name="android:windowEnterAnimation">@android:anim/slide_in_left</item> <item name="android:windowExitAnimation">@android:anim/slide_out_right</item> </style> </resources>
Implement our dialog layout, /res/layout/dialoglayout.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"/> <Button android:id="@+id/dismiss" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dismiss"/> </LinearLayout>
MainActivity.java
package com.example.animationdialog; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.app.Activity; import android.app.Dialog; public class MainActivity extends Activity { Button btnOpenDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnOpenDialog = (Button)findViewById(R.id.opendialog); btnOpenDialog.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { openDialog(); }}); } private void openDialog(){ final Dialog dialog = new Dialog(MainActivity.this); dialog.setTitle("Animation Dialog"); dialog.setContentView(R.layout.dialoglayout); dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; Button btnDismiss = (Button)dialog.getWindow().findViewById(R.id.dismiss); btnDismiss.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { dialog.dismiss(); }}); dialog.show(); } }
Main layout:
<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" > <Button android:id="@+id/opendialog" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="@dimen/padding_medium" android:text="Open Dialog" tools:context=".MainActivity" /> </RelativeLayout>
Download the files.
-- Delivered by Feed43 service
Related Posts
There is no other posts in this category.Popular
-
[Gameloft] Wonder Zoo S40, S60v3, S60v5, Symbian^3, BellaGameloft has just released this new great game " Wonder Zoo " in 2012, a zoo management g…
-
Andy (Siri for Android) v4.3 APKAndy is a voice controlled access to encyclopedic information on a vast array of topics. Ask anyt…
-
[Android] Talking Tom Cat 2 Free Download [mediafire]Talking Tom Cat 2 Free has been a fun and great game for relaxing since its first release. Accordi…
-
TNA Wrestling iMPACT v1.0.2 (Paid Version) Android Apk Game DownloadTNA Wrestling iMPACT v1.0.2 Requirements: 2.0.1 Strike, stomp, grapple and throw your way to t…
-
[Gameloft] Zombie Wood S40, S60v3, S60v5 & AndroidZombiewood is the latest shooter game for Android devices as well as Symbian Phones from Gameloft …
-
Muffin Knight v1.7 (Paid Version) Android Apk Game DownloadFootball Manager Handheld 2012 v3.5 Requirements: Android v2.2+ Overview: The World’s best-sell…
-
Soul Calibur will arrive on the App Store January 19Another great historical and console game coming soon on the App Store. We are talking about the fa…
Post a Comment
Post a Comment