Archive for 'Background Image'

Give background image for a view

The following code gives a background image for a view.

UIColor* tmpColor=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"image.png"]]; 
    self.view.backgroundColor=tmpColor; 
    [tmpColor release]; 

Setting TableView Background image

tableView background image

UIImage *backgroundImage = [UIImage imageNamed:@"body.png"];

UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];

//[self.t setBackgroundView:backgroundView];

tblView.backgroundView = backgroundView;

Tween Animation in Android

Tween Animation

 

A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object. So, if you have a TextView object, you can move, rotate, grow, or shrink the text. If it has a background image, the background image will be transformed along with the text. The animation package (android.view.animation) provides all the classes used in a tween animation.

 

A sequence of animation instructions defines the tween animation, defined by either XML or Android code. As with defining a layout, an XML file is recommended because it’s more readable, reusable, and swappable than hard-coding the animation. In the example below, XML is used.

 

The animation instructions define the transformations that you want to occur, when they will occur, and how long they should take to apply. Transformations can be sequential or simultaneous – for example, you can have the contents of a TextView move from left to right, and then rotate 180 degrees, or you can have the text move and rotate simultaneously. Each transformation takes a set of parameters specific for that transformation (starting size and ending size for size change, starting angle and ending angle for rotation, and so on), and also a set of common parameters (for instance, start time and duration). To make several transformations happen simultaneously, give them the same start time; to make them sequential, calculate the start time plus the duration of the preceding transformation.

 

The animation XML file belongs in the res/anim/ directory of your Android project. The file must have a single root element: this will be either a single <alpha>, <scale>,<translate>, <rotate>, interpolator element, or <set> element that holds groups of these elements (which may include another <set>). By default, all animation instructions are applied simultaneously. To make them occur sequentially, you must specify the startOffset attribute, as shown in the example below.

 

The following XML simultaneously spin and rotate a View object.

 

<set android:shareInterpolator=”false”>

<scale

android:interpolator=”@android:anim/accelerate_decelerate_interpolator”

android:fromXScale=”1.0″

android:toXScale=”1.4″

android:fromYScale=”1.0″

android:toYScale=”0.6″

android:pivotX=”50%”

android:pivotY=”50%”

android:fillAfter=”false”

android:duration=”700″ />

<set android:interpolator=”@android:anim/decelerate_interpolator”>

<scale

android:fromXScale=”1.4″

android:toXScale=”0.0″

android:fromYScale=”0.6″

android:toYScale=”0.0″

android:pivotX=”50%”

android:pivotY=”50%”

android:startOffset=”700″

android:duration=”400″

android:fillBefore=”false” />

<rotate

android:fromDegrees=”0″

android:toDegrees=”-45″

android:toYScale=”0.0″

android:pivotX=”50%”

android:pivotY=”50%”

android:startOffset=”700″

android:duration=”400″ />

</set>

</set>

 

Some values, such as pivotX, can be specified relative to the object itself or relative to the parent. Be sure to use the proper format for what you want (“50″ for 50% relative to the parent, or “50%” for 50% relative to itself).

 

You can determine how a transformation is applied over time by assigning an Interpolator. Android includes several Interpolator subclasses that specify various speed curves: for instance, AccelerateInterpolator tells a transformation to start slow and speed up. Each one has an attribute value that can be applied in the XML.

 

With this XML saved as star_jump.xml in the res/anim/ directory of the project, the following code will reference it and apply it to an ImageView object from the layout.

 

ImageView imgView;

Animation tweenAnimation;

 

imgView = (ImageView) findViewById(R.id.imgView);

tweenAnimation = AnimationUtils.loadAnimation(this, R.anim.star_jump);

imgView.startAnimation(tweenAnimation);

 

As an alternative to startAnimation(), you can define a starting time for the animation with Animation.setStartTime(), then assign the animation to the View with View.setAnimation().

 

Incoming search terms:

  • android text tweening animation example
  • android tween animation text example
  • tween animation in android

Two useful functionality for Cocos2d:

SpriteSheets:
Sprite animations are achieved by having a number of animation frames,of an image called a spritesheets,and moving through each of the frame quickly to achieve the animation.

here is an example:

Read the rest of this entry

Creating a custom Emulator Skin For Android

Create A Layout:(Don’t associate any extension with the file)

parts {

device {
display {
width   480
height  800
x       0
y       0
}
}

portrait {
background {
image   background_port.png
}
buttons {
back {
image back_sel.png
x 88
y 938
}
soft-left {
image menu_sel.png
x 210
y 938
}
home {
image home_sel.png
x 328
y 938
}
search {
image search_sel.png
x 447
y 938
}

}
}

landscape {
background {
image   background_land.png
}

buttons {
back {
image land_back_sel.png
x 938
y 451
}
soft-left {
image land_menu_sel.png
x 938
y 332
}
home {
image land_home_sel.png
x 938
y 214
}
search {
image land_search_sel.png
x 938
y 92
}

}
}

}

layouts {
portrait {
width     583
height    1149
color     0xe0e0e0
event     EV_SW:0:1

part1 {
name    portrait
x       0
y       0
}

part2 {
name    device
x       52
y       129
}
}

landscape {
width     1149
height    583
color     0xe0e0e0
event     EV_SW:0:0

part1 {
name    landscape
x       0
y       0
}

part2 {
name    device
x       129
y       531
rotation  3
}
}
}

network {
speed  full
delay  none
}

Read the rest of this entry

Incoming search terms:

  • android emulator custom skin file
We Can Build Your App for You. Lets Get Started !