i would like to set position of my view. There are the methods setX/setY or setLeft/setTop but these methods are available since API 11. What is the solution in order to have this fonctionnality in other API.
            Asked
            
        
        
            Active
            
        
            Viewed 2,038 times
        
    3 Answers
2
            
            
        It depends on which layout you're using. With RelativeLayout you can do the following:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)child.getLayoutParams();
layoutParams.leftMargin = x;
layoutParams.topMargin = y;
child.setLayoutParams(layoutParams);
        ThomasW
        
- 16,981
 - 4
 - 79
 - 106
 
- 
                    check out this answer http://stackoverflow.com/questions/12195768/android-use-of-view-setx-and-sety-in-api-8/28151869#28151869 – Orr Jan 26 '15 at 14:22
 
0
            
            
        try to override onDraw method and set translation x/y your canvas ?
@Override
protected function onDraw(Canvas c){
    c.save();
    c.translate(x,y);
    c.restore();
}
I think it's not a good solution but it the only idea i had.
        throrin19
        
- 17,796
 - 4
 - 32
 - 52
 
0
            
            
        The only thing I could get to work 'out-of-the-box' was setting the views padding.
View.setPadding(left, top, right, bottom);
It isn't the best solution but it will work on API's older than 11 and will simulate moving the view in a X, Y fashion.
Hope that helps!
        Jusarg.com
        
- 1
 - 1