<anchor>元素,类似html中的锚
该元素总是要规定一个任务(go,prev,refresh)。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="first" title="my first wml_card">
<p>
<anchor>回去
<go href="/blog_article/wap_test.wml" />
</anchor>
</p>
</card>
</wml>
上面的例子中,点击回去后,会跳转到wap_test.wml
<a>标签会执行go任务。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="first" title="my first wml_card">
<p>
<a href="/blog_article/2.wml">去2</a>
</p>
</card>
</wml>
上面的例子中可以看出和html中的a元素一样。
class PanelSwitcher extends FrameLayout {
private static final int MAJOR_MOVE = 60;
private static final int ANIM_DURATION = 400;
private GestureDetector mGestureDetector;
private int mCurrentView;
private View mChild, mHistoryView;
private View children[];
private int mWidth;
private TranslateAnimation inLeft;
private TranslateAnimation outLeft;
private TranslateAnimation inRight;
private TranslateAnimation outRight;
private static final int NONE = 1;
private static final int LEFT = 2;
private static final int RIGHT = 3;
private int mPreviousMove;
public PanelSwitcher(Context context, AttributeSet attrs) {
super(context, attrs);
mCurrentView = 0;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
int dx = (int) (e2.getX() - e1.getX());
// don't accept the fling if it's too short
// as it may conflict with a button push
if (Math.abs(dx) > MAJOR_MOVE && Math.abs(velocityX) > Math.abs(velocityY)) {
if (velocityX > 0) {
moveRight();
} else {
moveLeft();
}
return true;
} else {
return false;
}
}
});
}
@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
mWidth = w;
inLeft = new TranslateAnimation(mWidth, 0, 0, 0);
outLeft = new TranslateAnimation(0, -mWidth, 0, 0);
inRight = new TranslateAnimation(-mWidth, 0, 0, 0);
outRight = new TranslateAnimation(0, mWidth, 0, 0);
inLeft.setDuration(ANIM_DURATION);
outLeft.setDuration(ANIM_DURATION);
inRight.setDuration(ANIM_DURATION);
outRight.setDuration(ANIM_DURATION);
}
protected void onFinishInflate() {
int count = getChildCount();
children = new View[count];
for (int i = 0; i < count; ++i) {
children[i] = getChildAt(i);
if (i != mCurrentView) {
children[i].setVisibility(View.GONE);
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
mGestureDetector.onTouchEvent(event);
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
void moveLeft() {
// <--
if (mCurrentView < children.length - 1 && mPreviousMove != LEFT) {
children[mCurrentView+1].setVisibility(View.VISIBLE);
children[mCurrentView+1].startAnimation(inLeft);
children[mCurrentView].startAnimation(outLeft);
children[mCurrentView].setVisibility(View.GONE);
mCurrentView++;
mPreviousMove = LEFT;
}
}
void moveRight() {
// -->
if (mCurrentView > 0 && mPreviousMove != RIGHT) {
children[mCurrentView-1].setVisibility(View.VISIBLE);
children[mCurrentView-1].startAnimation(inRight);
children[mCurrentView].startAnimation(outRight);
children[mCurrentView].setVisibility(View.GONE);
mCurrentView--;
mPreviousMove = RIGHT;
}
}
int getCurrentIndex() {
return mCurrentView;
}
}
noop
是no operation的缩写,表示不做任何事。用于覆盖卡片组级别的元素。
do
用于在用户点击屏幕上的某个文字时,启动一个任务。
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Tutorial">
<do type="accept" label="Answer">
<go href="#card2"/>
</do>
<p>
<select name="name">
<option value="HTML">HTML Tutorial</option>
<option value="XML">XML Tutorial</option>
<option value="WAP">WAP Tutorial</option>
</select>
</p>
</card>
<card id="card2" title="Answer">
<p>
You selected: $(name)
</p>
</card>
</wml>
在这个例子中,当点击do的文字Answer,会跳转到卡片card2
注意在card2中,会将变量为name的东西输出。变量name我们在card1中的select元素中的name属性设置。
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Tutorial">
<do type="accept" label="Answer">
<go href="#card2">
<setvar name="i" value="500"/>
</go>
</do>
<p>
<select name="name">
<option value="HTML">HTML Tutorial</option>
<option value="XML">XML Tutorial</option>
<option value="WAP">WAP Tutorial</option>
</select>
</p>
</card>
<card id="card2" title="Answer">
<p>
You selected: $(i)
</p>
</card>
</wml>
这个例子中输出的是变量i,变量i是我们在点击do,执行go指令的时候,设置的。
do-type属性:accept
prev
help
reset
options
delete
unknown
x-*
vnd.*