Sunday, July 22, 2012

Sliding Panel From Top to Bottom



Click Here To Download Source Code

Package Name   :    selva.sliding

Project Name     :    Sliding2

Version              :    1.5 ( Supports 1.5 and above versions)


main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
        <selva.sliding.Sliding
            android:id="@+id/sliding1"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="1px"
            android:background="#ffffff">
                <CheckBox android:id="@+id/check1"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                        android:text="Option1" />
                <CheckBox android:id="@+id/check2"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                         android:text="Option2" />
                <CheckBox android:id="@+id/check3"
                        android:textColor="#FFFFFF"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                         android:text="Option3" />
        </selva.sliding.Sliding>

    <Button android:id="@+id/show1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/expand"/>
</LinearLayout>
 

 Sliding2Activity.java

package selva.sliding;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class Sliding2Activity extends Activity
{
      CheckBox c1,c2,c3;
        int key=0;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Sliding popup = (Sliding) findViewById(R.id.sliding1);
        popup.setVisibility(View.GONE);

                final Button btn=(Button)findViewById(R.id.show1);
                btn.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                                if(key==0){
                                        key=1;
                                        popup.setVisibility(View.VISIBLE);
                                        btn.setBackgroundResource(R.drawable.expand);
                                }
                                else if(key==1){
                                        key=0;
                                        popup.setVisibility(View.GONE);
                                        btn.setBackgroundResource(R.drawable.expand);
                                }
                        }
                });

        }
    }
 



 Sliding.java

package selva.sliding;


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 Sliding extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public Sliding(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public Sliding(Context context) {
super(context);
init();
}
private void init() {
innerPaint = new Paint();
innerPaint.setARGB(225, 75, 75, 75); //gray
innerPaint.setAntiAlias(true);
borderPaint = new Paint();
borderPaint.setARGB(255, 255, 255, 255);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(2);
}
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);
}
}


Output : 














































click expand icon

 








Click Here To Download Source Code





1 comment:

  1. Welcome to Jammy Casino - Hotels near I-10 - JTM Hub
    We bring you all 거제 출장안마 the casino 동두천 출장안마 games and slots with real cash prizes! We also bring you 제천 출장샵 a great 김천 출장샵 choice of new 군포 출장안마 slots and other casino games.

    ReplyDelete