-
switch (position) {
-
case LEFT_TOP:
-
for (int i = 0; i < menuResIds.length; i++) {
-
int width_padding = mWIDTH / ((menuResIds.length - 1) * 2);
-
int height_padding = mHEIGHT / ((menuResIds.length - 1) * 2);
-
ImageView imageView = new ImageView(mContext);
-
imageView.setimageResource(menuResIds[i]);
-
addView(imageView);
-
.getLayoutParams();
-
params.leftMargin = mWIDTH / 2
-
- ((menuResIds.length - i - 1) * width_padding);
-
params.topMargin = mHEIGHT / 2 - i * height_padding;
-
}
-
break;
-
case RIGHT_TOP:
-
for (int i = 0; i < menuResIds.length; i++) {
-
int width_padding = mWIDTH / ((menuResIds.length - 1) * 2);
-
int height_padding = mHEIGHT / ((menuResIds.length - 1) * 2);
-
ImageView imageView = new ImageView(mContext);
-
imageView.setimageResource(menuResIds[i]);
-
addView(imageView);
-
.getLayoutParams();
-
params.rightMargin = mWIDTH / 2
-
- ((menuResIds.length - i - 1) * width_padding);
-
params.topMargin = mHEIGHT / 2 - i * height_padding;
-
}
-
break;
-
case RIGHT_BottOM:
-
for (int i = 0; i < menuResIds.length; i++) {
-
int width_padding = mWIDTH / ((menuResIds.length - 1) * 2);
-
int height_padding = mHEIGHT / ((menuResIds.length - 1) * 2);
-
ImageView imageView = new ImageView(mContext);
-
imageView.setimageResource(menuResIds[i]);
-
addView(imageView);
-
.getLayoutParams();
-
params.rightMargin = mWIDTH / 2
-
- ((menuResIds.length - i - 1) * width_padding);
-
}
-
break;
-
case LEFT_BottOM:
-
for(int i = 0; i < menuResIds.length; i++){
-
int width_padding = mWIDTH / ((menuResIds.length - 1) * 2);
-
int height_padding = mHEIGHT / ((menuResIds.length -1) * 2);
-
ImageView imageView = new ImageView(mContext);
-
imageView.setimageResource(menuResIds[i]);
-
addView(imageView);
-
LayoutParams params = (FrameLayout.LayoutParams)imageView.getLayoutParams();
-
params.leftMargin = mWIDTH / 2 - ((menuResIds.length - i - 1) * width_padding);
-
}
-
break;
-
default:
-
break;
-
}
-
}
-
private OnClickListener listener = new OnClickListener() {
-
public void onClick(View v) {
-
if (!bMenuShow) {
-
startAnimationIn(PathMenuView.this, 300);
-
} else {
-
startAnimationOut(PathMenuView.this, 300);
-
}
-
bMenuShow = !bMenuShow;
-
}
-
};
-
/**
-
* 菜单隐藏动画.
-
*
-
* @param group
-
* @param duration
-
*/
-
private void startAnimationIn(ViewGroup group, int duration) {
-
for (int i = 1; i < group.getChildCount(); i++) {
-
ImageView imageview = (ImageView) group.getChildAt(i);
-
imageview.setVisibility(0);
-
.getLayoutParams();
-
Animation animation = null;
-
switch (position) {
-
case LEFT_TOP:
-
animation = new TranslateAnimation(0F,-mlp.leftMargin+xOffset,0F,-mlp.topMargin + yOffset);
-
break;
-
case RIGHT_TOP:
-
animation = new TranslateAnimation(mlp.rightMargin - xOffset,0F,-mlp.topMargin + yOffset,0F);
-
break;
-
case LEFT_BottOM:
-
animation = new TranslateAnimation(0F, -mlp.leftMargin+ xOffset, 0F, -yOffset + mlp.bottomMargin);
-
break;
-
case RIGHT_BottOM:
-
animation = new TranslateAnimation(mlp.rightMargin-xOffset,0F,-yOffset + mlp.bottomMargin, 0F);
-
break;
-
default:
-
break;
-
}
-
animation.setFillAfter(true);
-
animation.setDuration(duration);
-
animation.setStartOffset((i * 100) / (-1 + group.getChildCount()));
-
animation.setInterpolator(new OvershootInterpolator(2F));
-
imageview.startAnimation(animation);
-
}
-
}
-
/**
-
*
-
* @param group
-
* @param duration
-
*/
-
private void startAnimationOut(ViewGroup group,int duration){
-
for (int i = 1; i < group.getChildCount(); i++) {
-
final ImageView imageview = (ImageView) group
-
.getChildAt(i);
-
MarginLayoutParams mlp = (MarginLayoutParams) imageview.getLayoutParams();
-
Animation animation = null;
-
switch (position) {
-
case LEFT_TOP:
-
animation = new TranslateAnimation(-mlp.leftMargin+xOffset,0F,-mlp.topMargin + yOffset,0F);
-
break;
-
case RIGHT_TOP:
-
animation = new TranslateAnimation(0F,mlp.rightMargin - xOffset,0F,-mlp.topMargin + yOffset);
-
break;
-
case LEFT_BottOM:
-
animation = new TranslateAnimation(-mlp.leftMargin+xOffset,0F, -yOffset + mlp.bottomMargin,0F);
-
break;
-
case RIGHT_BottOM:
-
animation = new TranslateAnimation(0F,mlp.rightMargin-xOffset, 0F,-yOffset + mlp.bottomMargin);
-
break;
-
default:
-
break;
-
}
-
animation.setFillAfter(true);animation.setDuration(duration);
-
animation.setStartOffset(((group.getChildCount()-i) * 100)
-
/ (-1 + group.getChildCount()));
-
animation.setInterpolator(new AnticipateInterpolator(2F));
-
imageview.startAnimation(animation);
-
}
-
}
-
}
第四步:PathTestActivity.java以及用到的布局文件main.xml代码如下:
PathTestActivity.java(基本没修改代码)代码如下:
[java] view plain copy
-
package com.tutor.path;
-
import android.app.Activity;
-
import android.os.Bundle;
-
public class PathTestActivity extends Activity {
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.main);
-
}
-
}
main.xml代码如下:
[java] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
-
xmlns:tutor=“http://schemas.android.com/apk/res/com.tutor.path”
-
android:layout_width=“fill_parent”
-
android:layout_height=“fill_parent”
-
android:orientation=“vertical” >
-
<com.tutor.path.PathMenuView
-
android:id="@+id/text"
-
android:layout_width=“fill_parent”
-
android:layout_height=“fill_parent”
-
tutor:position=“right_bottom”
-
/>
最后
下面是辛苦给大家整理的学习路线
-
android:layout_height=“fill_parent”
-
android:orientation=“vertical” >
-
<com.tutor.path.PathMenuView
-
android:id="@+id/text"
-
android:layout_width=“fill_parent”
-
android:layout_height=“fill_parent”
-
tutor:position=“right_bottom”
-
/>
最后
下面是辛苦给大家整理的学习路线
[外链图片转存中…(img-cse5ggaX-1643518121306)]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。