Search code examples
androidandroid-relativelayoutabsolutelayout

How to replcae AbsoluteLayout with RelativeLayout


I have a Class that used in it below code

this.guageBack= (AbsoluteLayout) findViewById(R.id.gaugeFrame);
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(this.needleWidth,this.needleHeight,this.needleX,this.needleY);
gaugeNeedle.setLayoutParams(params);

AbsoluteLayout deprecated so When I want to use RelativeLayout I have not replcement for

AbsoluteLayout.LayoutParams(this.needleWidth,this.needleHeight,this.needleX,this.needleY);

Because it accept two args like below

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(needleWidth, needleHeight);

What should I do?


Solution

  • Just add this code instead of yours

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(needleWidth, needleHeight);
            params.topMargin = needleY;
            params.leftMargin = needleX;