帮我看一下这段代码,为什么anchor.getTop的值是一直不变。public class QuickAction extends CustomPopupWindow {
private final View root;
private final ImageView mArrowUp;
private final ImageView mArrowDown;
private final Animation mTrackAnim;
private final LayoutInflater inflater;
private final Context context;
public static final int ANIM_GROW_FROM_LEFT = 1;
public static final int ANIM_GROW_FROM_RIGHT = 2;
public static final int ANIM_GROW_FROM_CENTER = 3;
public static final int ANIM_AUTO = 4;
private int animStyle;
private boolean animateTrack;
private ViewGroup mTrack;
private ArrayList<ActionItem> actionList;
/**
* Constructor
*
* @param anchor {@link View} on where the popup should be displayed
*/
public QuickAction(View anchor) {
super(anchor);
System.out.println("anchor6=1======="+anchor);
actionList = new ArrayList<ActionItem>();
context = anchor.getContext();
System.out.println("anchor.getContext()64======="+anchor.getContext());
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
root = (ViewGroup) inflater.inflate(R.layout.quickaction, null);
System.out.println("root 68===="+root);
mArrowDown = (ImageView) root.findViewById(R.id.arrow_down);
mArrowUp = (ImageView) root.findViewById(R.id.arrow_up);
setContentView(root);
System.out.println("root 73===="+root);
mTrackAnim = AnimationUtils.loadAnimation(anchor.getContext(), R.anim.rail);
mTrackAnim.setInterpolator(new Interpolator() {
public float getInterpolation(float t) {
// Pushes past the target area, then snaps back into place.
// Equation for graphing: 1.2-((x*1.6)-1.1)^2
final float inner = (t * 1.55f) - 1.1f;
return 1.2f - inner * inner;
}
});
mTrack = (ViewGroup) root.findViewById(R.id.tracks);
animStyle = ANIM_AUTO;
animateTrack = true;
} /**
* Animate track
*
* @param animateTrack flag to animate track
*/
public void animateTrack(boolean animateTrack) {
this.animateTrack = animateTrack;
}
/**
* Set animation style
*
* @param animStyle animation style, default is set to ANIM_AUTO
*/
public void setAnimStyle(int animStyle) {
this.animStyle = animStyle;
} /**
* Add action item
*
* @param action {@link ActionItem}
*/
public void addActionItem(ActionItem action) {
actionList.add(action);
}
/**
* Show popup window
*/
public void show () {
preShow(); int[] location = new int[2];
anchor.getLocationOnScreen(location); Rect anchorRect = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1]
+ anchor.getHeight());
System.out.println("anchorRect=130======"+anchorRect);
System.out.println("anchor.getWidth()======"+anchor.getWidth());
System.out.println("anchor.getHeight()======"+anchor.getHeight());
root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int rootWidth = root.getMeasuredWidth();
int rootHeight = root.getMeasuredHeight();
System.out.println("rootWidth======"+rootWidth);
System.out.println("rootHeight======"+rootHeight);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
//int screenHeight = windowManager.getDefaultDisplay().getHeight(); int xPos = (screenWidth - rootWidth) / 2;
int yPos = anchorRect.top - rootHeight; boolean onTop = true;
System.out.println("ontop====="+onTop);
// display on bottom
if (rootHeight > anchor.getTop()) {
yPos = anchorRect.bottom;
onTop = false;
}
System.out.println("ontop====="+onTop);
System.out.println("anchor.getTop------------"+anchor.getTop());
showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX());
setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);
createActionList();
window.showAtLocation(this.anchor, Gravity.NO_GRAVITY, xPos, yPos);
if (animateTrack) mTrack.startAnimation(mTrackAnim);
}
private final View root;
private final ImageView mArrowUp;
private final ImageView mArrowDown;
private final Animation mTrackAnim;
private final LayoutInflater inflater;
private final Context context;
public static final int ANIM_GROW_FROM_LEFT = 1;
public static final int ANIM_GROW_FROM_RIGHT = 2;
public static final int ANIM_GROW_FROM_CENTER = 3;
public static final int ANIM_AUTO = 4;
private int animStyle;
private boolean animateTrack;
private ViewGroup mTrack;
private ArrayList<ActionItem> actionList;
/**
* Constructor
*
* @param anchor {@link View} on where the popup should be displayed
*/
public QuickAction(View anchor) {
super(anchor);
System.out.println("anchor6=1======="+anchor);
actionList = new ArrayList<ActionItem>();
context = anchor.getContext();
System.out.println("anchor.getContext()64======="+anchor.getContext());
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
root = (ViewGroup) inflater.inflate(R.layout.quickaction, null);
System.out.println("root 68===="+root);
mArrowDown = (ImageView) root.findViewById(R.id.arrow_down);
mArrowUp = (ImageView) root.findViewById(R.id.arrow_up);
setContentView(root);
System.out.println("root 73===="+root);
mTrackAnim = AnimationUtils.loadAnimation(anchor.getContext(), R.anim.rail);
mTrackAnim.setInterpolator(new Interpolator() {
public float getInterpolation(float t) {
// Pushes past the target area, then snaps back into place.
// Equation for graphing: 1.2-((x*1.6)-1.1)^2
final float inner = (t * 1.55f) - 1.1f;
return 1.2f - inner * inner;
}
});
mTrack = (ViewGroup) root.findViewById(R.id.tracks);
animStyle = ANIM_AUTO;
animateTrack = true;
} /**
* Animate track
*
* @param animateTrack flag to animate track
*/
public void animateTrack(boolean animateTrack) {
this.animateTrack = animateTrack;
}
/**
* Set animation style
*
* @param animStyle animation style, default is set to ANIM_AUTO
*/
public void setAnimStyle(int animStyle) {
this.animStyle = animStyle;
} /**
* Add action item
*
* @param action {@link ActionItem}
*/
public void addActionItem(ActionItem action) {
actionList.add(action);
}
/**
* Show popup window
*/
public void show () {
preShow(); int[] location = new int[2];
anchor.getLocationOnScreen(location); Rect anchorRect = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1]
+ anchor.getHeight());
System.out.println("anchorRect=130======"+anchorRect);
System.out.println("anchor.getWidth()======"+anchor.getWidth());
System.out.println("anchor.getHeight()======"+anchor.getHeight());
root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int rootWidth = root.getMeasuredWidth();
int rootHeight = root.getMeasuredHeight();
System.out.println("rootWidth======"+rootWidth);
System.out.println("rootHeight======"+rootHeight);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
//int screenHeight = windowManager.getDefaultDisplay().getHeight(); int xPos = (screenWidth - rootWidth) / 2;
int yPos = anchorRect.top - rootHeight; boolean onTop = true;
System.out.println("ontop====="+onTop);
// display on bottom
if (rootHeight > anchor.getTop()) {
yPos = anchorRect.bottom;
onTop = false;
}
System.out.println("ontop====="+onTop);
System.out.println("anchor.getTop------------"+anchor.getTop());
showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX());
setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);
createActionList();
window.showAtLocation(this.anchor, Gravity.NO_GRAVITY, xPos, yPos);
if (animateTrack) mTrack.startAnimation(mTrackAnim);
}
解决方案 »
- Android自定义View的一个问题
- 如何让Android buttton按钮美化?请大家帮帮我
- 我想让Dialog中在启动一个Dialog,里面的Dialog该怎样写
- 能不能通过android的应用,修改引导系统的UBOOT?
- 有没有谁有Android的源代码????
- 求助 :通过 Parcelable 在两个activity中间传递数据的问题
- fragment 父类引用指向子类引用报错
- 请神帮忙解释getContentResolver().update参数
- 在unity3D中怎么利用PlayerPrefs显示最高分
- Android studio编程问题。
- android开发google地图 地图显示问题
- MyEclipse配置SDK失败
super(anchor);怎样获取父类的父类,因为想得到,全部,而不是局部,请高手帮忙啊。