Friday, March 23, 2012


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



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
package com.pack.coderzheaven;
 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
 
public class SlidingPanel extends LinearLayout
{
    private Paint   innerPaint, borderPaint ;
 
    public SlidingPanel(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
 
    public SlidingPanel(Context context) {
        super(context);
        init();
    }
 
    private void init() {
        innerPaint = new Paint();
        innerPaint.setARGB(100, 25, 25, 75); //gray
        innerPaint.setAntiAlias(true);
 
        borderPaint = new Paint();
        borderPaint.setARGB(255, 255, 255, 255);
        borderPaint.setAntiAlias(true);
        borderPaint.setStyle(Style.STROKE);
        borderPaint.setStrokeWidth(5);
    }
 
    public void setInnerPaint(Paint innerPaint) {
        this.innerPaint = innerPaint;
    }
 
    public void setBorderPaint(Paint borderPaint) {
        this.borderPaint = borderPaint;
    }
 
    @Override
    protected void dispatchDraw(Canvas canvas) {
 
        RectF drawRect = new RectF();
        drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
 
        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
        canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
 
        super.dispatchDraw(canvas);
    }
}
This is the layout for the Panel window that comes up. Actually this java file creates gradiant only. No visual components are created with this code.
Now the main.xml, the place where “SlidingPanel ” is used.
Copy this code to your main.xml file
?
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
62
63
64
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:gravity="bottom"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
 
    <ImageButton
            android:id="@+id/show_popup_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:background="@drawable/open"
            />
 
    <com.pack.coderzheaven.SlidingPanel
            android:id="@+id/popup_window"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="left"
            android:padding="1px"
            android:background="@drawable/white">
 
        <LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:background="@drawable/gradient_bar">
 
            <TextView
                    android:id="@+id/site_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textSize="16px"
                    android:text="CoderzHeaven"
                    android:layout_gravity="center"
                    android:layout_alignParentLeft="true"
                    android:textColor="@drawable/black"
                    android:layout_weight="1"
                    android:layout_marginLeft="5px"/>
 
            <ImageButton android:id="@+id/hide_popup_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="true"
                    android:layout_margin="2px"
                    android:layout_gravity="center"
                    android:background="@drawable/close"/>
 
        </LinearLayout>
 
        <TextView    android:id="@+id/site_description"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@drawable/black"
                    android:textStyle="italic"
                    android:layout_margin="5px"/>
 
    </com.pack.coderzheaven.SlidingPanel>
 
</LinearLayout>

No comments: