Search code examples
graphicstouchlistenerparentscaling

Parent View Scaling OnClickListener


Solution

Original: Window Service > Parent Layout > Views
Fixed: Window Service > Parent Layout > Parent Layout 2 > Views

You cannot use a parent layout that is not a child to another layout before being added to window service. Only graphics will scale if you do so.


Issue

I have a RelativeLayout that parents some views like a TextView, SeekBar, and a Button. Using setScaleX/Y, I am successfully able to scale the views visually. A problem I now have is that although the graphics have scaled, the onClickListeners touch area have not scaled along with the graphics. I need to touch the original position in order to trigger any of these events. I want the touch area to scale with the graphics without scaling the children individually.

Current Scaling Code:

size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
   @Override
   public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      /** Max Progress is 100 **/
      float scale = 1.0f;
      scale = scale + 0.01f * progress;

      /** mLayout is Parent Layout **/
      mLayout.setScaleX(scale);
      mLayout.setScaleY(scale);
      mLayout.invalidate();
  }

  @Override
  public void onStartTrackingTouch(SeekBar seekBar) {
  }

  @Override
  public void onStopTrackingTouch(SeekBar seekBar) {
  }
});

Solution

  • Solution

    Original: Window Service > Parent Layout > Views
    Fixed: Window Service > Parent Layout > Parent Layout 2 > Views
    

    You cannot use a parent layout that is not a child to another layout before being added to window service. Only graphics will scale if you do so.