Blackberry - how to create a layout like sliding drawer android
Does anyone know how to create layout component in blackberry that behave like android's sliding draw开发者_StackOverflow中文版er?
thx.
Haven't actually done it. But I think the biggest difficulty here is the Sliding animation part and the visibility IMHO. You should first work on the animation for the sliding effect. Then on the Manager itself.
Touch devices come with another difficulty... you have to program the slider touch event so that it follows the gesture.
hey its really a brilliant idea to have such layouts for blackberry. it is quite challenging to get it done. we have to play with custom layouts. first thing requied is the knowledge of customization of managers. I believe we can also use pop up screen to slide it up. manager on top of an pop up screen. secondly, the Gusture api for side scrolling. all the best buddy.
Please check the below source code in which i created a manager class. Just add whatever you want to slide to that manager and use it. Change according to your requirement.
package mypackage;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
public class SlidingDrawer extends Manager {
final static int STATE_VIEW = 1;
final static int STATE_HIDE = STATE_VIEW+1;
final static int STATE_SLIDE_DOWN = STATE_HIDE+1;
final static int STATE_SLIDE_UP = STATE_SLIDE_DOWN+1;
final static int MAX_NO_OF_STATES = STATE_SLIDE_UP+1;
static int CURRENT_STATE = STATE_VIEW;
int i = 0;
LabelField _lbl_hero;
public SlidingDrawer(long arg0) {
super(arg0);
// TODO Auto-generated constructor stub
init();
}
private void init()
{
_lbl_hero = new LabelField("Hero testing Every thign....");
this.add(_lbl_hero);
}
protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
switch(CURRENT_STATE)
{
case STATE_VIEW:
super.paint(graphics);
break;
case STATE_HIDE:
break;
case STATE_SLIDE_DOWN:
super.paint(graphics);
if(i<this.getHeight())
{
this.getField(0).setPadding(i++, 0, 0, 0);
invalidate();
}
else
{
CURRENT_STATE = STATE_HIDE;
}
break;
case STATE_SLIDE_UP:
super.paint(graphics);
if( i > 0 )
{
this.getField(0).setPadding(i--, 0, 0, 0);
invalidate();
}
else
{
CURRENT_STATE = STATE_VIEW;
}
break;
}
}
public void setState(int state)
{
if(state < MAX_NO_OF_STATES)
{
CURRENT_STATE = state;
}
else
Dialog.alert("Invalid State....");
}
protected boolean touchEvent(TouchEvent message) {
// TODO Auto-generated method stub
if(CURRENT_STATE == STATE_VIEW)
{
i=0;
CURRENT_STATE = STATE_SLIDE_DOWN;
invalidate();
}
else if(CURRENT_STATE == STATE_HIDE)
{
// i = this.getField(0).getContentRect().y;
CURRENT_STATE = STATE_SLIDE_UP;
invalidate();
}
return super.touchEvent(message);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
setExtent(360, 100);//Width and Height of the Childs
}
}
Please change this code according to your requirement and use it.
精彩评论