Friday, March 23, 2012

How to show a sliding window from below in Android? --2



How to show a sliding window from below in Android?  --2



Make sure you have all the resources(images) for the xml.
Now create a folder named “anim” inside “res” folder and create an xml named “popup_hide.xml” and another one named “popup_show.xml”
popup_hide.xml
?
Drag and copy the code
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
    <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="750"/>
</set>
popup_show.xml
?
Drag and copy the code
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
    <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="750"/>
</set>
These two files create the animation for the window.
Now create file named gradient_bar.xml in the “res/drawable” folder and copy this code into it.
This is applied as background for the title in the sliding window.
You can edit the animation files to change the duration of the window coming.
Now the main java file
The file is named “PopUpAnimationDemo.java
?
Drag and copy the code
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.pack.coderzheaven;
 
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.ImageButton;
import android.widget.TextView;
 
public class PopUpAnimationDemo extends Activity {
 
    private Animation animShow, animHide;
 
    @Override
    public void onCreate(Bundle icicle) {
 
        super.onCreate(icicle);
        setContentView(R.layout.main);
        initPopup();
    }
 
    private void initPopup() {
 
        final SlidingPanel popup = (SlidingPanel) findViewById(R.id.popup_window);
 
        // Hide the popup initially.....
        popup.setVisibility(View.GONE);
 
        animShow = AnimationUtils.loadAnimation( this, R.anim.popup_show);
        animHide = AnimationUtils.loadAnimation( this, R.anim.popup_hide);
 
        final ImageButton   showButton = (ImageButton) findViewById(R.id.show_popup_button);
        final ImageButton   hideButton = (ImageButton) findViewById(R.id.hide_popup_button);
        showButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                popup.setVisibility(View.VISIBLE);
                popup.startAnimation( animShow );
                showButton.setEnabled(false);
                hideButton.setEnabled(true);
        }});
 
        hideButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                popup.startAnimation( animHide );
                showButton.setEnabled(true);
                hideButton.setEnabled(false);
                popup.setVisibility(View.GONE);
        }});
 
        final TextView locationName = (TextView) findViewById(R.id.site_name);
        final TextView locationDescription = (TextView) findViewById(R.id.site_description);
 
        locationName.setText("CoderzHeaven");
        locationDescription.setText("Heaven of all working codes"
                                    + " A place where you can ask, share & even shout for code! Let’s share a wide range of technology here." +
                                    " From this site you will get a lot of working examples in your favorite programming languages!." +
                                    " Always remember we are only one comment away from you… Let’s shorten the distance between your doubts and your answers…");
 
    }
}
Here is the Strings.xml i
?
Drag and copy the code
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="app_name">Sliding Window Demo</string>
</resources>
Now create a file named colors.xml in the res/values folder and copy this into it
?
Drag and copy the code
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
<?xml version="1.0" encoding="utf-8"?>
<resources>
     <drawable name="white">#ffffff</drawable>
    <drawable name="black">#000000</drawable>
    <drawable name="green">#347C2C</drawable>
    <drawable name="pink">#FF00FF</drawable>
    <drawable name="violet">#a020f0</drawable>
    <drawable name="grey">#778899</drawable>
    <drawable name="red">#C11B17</drawable>
    <drawable name="yellow">#FFFF8C</drawable>
    <drawable name="PowderBlue">#b0e0e6</drawable>
    <drawable name="brown">#2F1700</drawable>
    <drawable name="Hotpink">#7D2252</drawable>
    <string name="select_Category">Select Category</string>
    <drawable name="darkgrey">#606060</drawable>
</resources>
Click on the ImagButton to open the sliding Window
Sliding Window
Sliding Window
Sliding Window

No comments: