click here to download source code
package Name : selva.sliding
project Name : Sliding3
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="horizontal"
android:gravity="right"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/show1"
android:layout_width="wrap_content"
android:layout_marginTop="250dp"
android:layout_height="wrap_content"
android:background="@drawable/prev_item" />
<selva.sliding.Sliding
android:id="@+id/sliding1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
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>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="right"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/show1"
android:layout_width="wrap_content"
android:layout_marginTop="250dp"
android:layout_height="wrap_content"
android:background="@drawable/prev_item" />
<selva.sliding.Sliding
android:id="@+id/sliding1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
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>
</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.prev_item);
}
else if(key==1){
key=0;
popup.setVisibility(View.GONE);
btn.setBackgroundResource(R.drawable.prev_item);
}
}
});
}
}
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.prev_item);
}
else if(key==1){
key=0;
popup.setVisibility(View.GONE);
btn.setBackgroundResource(R.drawable.prev_item);
}
}
});
}
}
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);
}
}
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 icon
click here to download source code