0

我想从传递给我的自定义视图的构造函数的标准属性中提取宽度规范和高度规范,这样当我想显示在活动锁定中旋转为纵向的视图时,我可以调整它们并作为新的布局参数传回。

我无法找到需要传递的 intarray 中的静态 int 值的名称以获取这些原始值。他们在哪里?

public static final int[] stdatts = {valForandroid:layout_width,...height,...gravity};
TypedArray natts = getContext().getResources().obtainAttributes(attrs, stdatts);
int widset = natts.getInteger(valForandroid:layout_width, 0);
int hitset = ....;
int gravset = .....;
if (orientIsV) 
  FrameLayout.LayoutParams reset = new FrameLayout.LayoutParams (widset, hitset, gravset);
else 
  FrameLayout.LayoutParams reset = new FrameLayout.LayoutParams (hitset, widset, gravset);

通过查看我实际通过的属性数组,我可以很容易地找到这些值,但这显然是一个非常肮脏且不可靠的修复

4

1 回答 1

0

不是我预期的答案——我放弃了尝试以这种方式处理这个问题——数据格式很难理解。这是扩展的 relativelayout 类的部分代码,该类旋转,保持其中的所有内容不变,它还保持左/右对齐正确并正确处理触摸事件。例如,它将允许嵌套的 Seekbar 位于任何方向,从而避免了对特殊情况下的 seekbar 的需要。

public void setOrientation() {
  if (rSource == RotateSetBy.globalStatic) {
    currRotate = PootleViewExtras.deviceOrient;
  }
  boolean isVert = currRotate == Orientations.up || currRotate == Orientations.down;
  if (lockSize > 0 && widthAtt < 0 && heightAtt < 0) {
    int lws = 0;
    int lhs = 0;
    if (isVert) {
      lws = widthAtt;
      lhs = heightAtt;
    } else {
      lhs = widthAtt;
      lws = heightAtt;
    }
    int setgrav = gravityAtt & 0x11; // messy but seems to do the right things
    if   (currRotate == Orientations.down ) {
      if ((gravityAtt & 0x2) != 0) setgrav |= 0x4;
      if ((gravityAtt & 0x4) != 0) setgrav |= 0x2;
      if ((gravityAtt & 0x20) != 0) setgrav |= 0x40;
      if ((gravityAtt & 0x40) != 0) setgrav |= 0x20;
    } else {
      setgrav = gravityAtt;
    }  

    FrameLayout.LayoutParams reset = new FrameLayout.LayoutParams (lws, lhs, setgrav);
    this.setLayoutParams(reset);
  }
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

  boolean isVert = currRotate == Orientations.up || currRotate == Orientations.down;
  if (isVert)  {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    lastWidth = this.getMeasuredWidth();
    lastHeight = this.getMeasuredHeight();
  } else {
    super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    lastHeight = this.getMeasuredWidth();
    lastWidth = this.getMeasuredHeight();
  }
  setMeasuredDimension(lastWidth,lastHeight);
  switch (currRotate) {
    case up:
      mForward.reset();
      mForward.postRotate(0);
      mForward.invert(mReverse); 
      break;
    case right:
      mForward.reset();
      mForward.postRotate(90,lastWidth/2,lastWidth/2);
      mForward.invert(mReverse); 
      break;
    case down:
      mForward.reset();
      mForward.postRotate(180,lastWidth/2,lastHeight/2);
      mForward.invert(mReverse); 
      break;
    case left:
      mForward.reset();
      mForward.postRotate(-90,lastHeight/2,lastHeight/2);
      mForward.invert(mReverse);
      break;
  }
}

@Override
protected void dispatchDraw(Canvas canvas) {
  if (currRotate == Orientations.up) {
    super.dispatchDraw(canvas);
  } else {
    canvas.save();
    canvas.concat(mForward);
    super.dispatchDraw(canvas);
    canvas.restore();
  }
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
//    if (currRotate == Orientations.up){
//      return super.dispatchTouchEvent(event);
//    } else {
  final float[] temp = mTemp;
  temp[0] = event.getX();
  temp[1] = event.getY();

  mReverse.mapPoints(temp);
  event.setLocation(temp[0], temp[1]);
  return super.dispatchTouchEvent(event);
//    }
于 2012-08-19T15:18:27.477 回答