androidanimationandroid-linearlayoutmovesetx

android , moving view in linearlayout


I made a linear layout and it contain some Image views . when i move one with (set X(view.get x + 10)) function, it moves... but it moves behind other views. that the view become hidden.

and the other problem is when i get X & Y of the view, its always 0,0. but the view is in the middle of the screen. what should I do??? should i give up with linear layout??

if(wichmov == "right" ){
    if(martin.getX() < width){
        martin.setX(martin.getX()+ deltax);
    }
    else if(wichmov == "left"){
        if(martin.getX() > 0){
            martin.setX(martin.getX()- deltax );
        }
    }
}

this is how i move it.


Solution

  • I just figured it out.

    I use a relative layout and then set the linear layout as match parent. After designing the background with the linear layout, I define an image view after the linear layout and inside of the relative layout, and then in Java, I set the position of it in the exact place I want it to (front of the special box of linear layout that I wanted it move), and width and height of it too.

    The following code will help you to place your view to the exact place of your screen you want it, and set its width and height:

    DisplayMetrics metrics = this.getResources().getDisplayMetrics(); //getting screen size
    width = metrics.widthPixels;
    height = metrics.heightPixels;
    
    view.setX(width *5/8); //setting the place
    view.setY(height/4);
    
    LayoutParams para = view.getLayoutParams(); //set size of view
    para.height = (int) (height/2);
    para.width = (int) (width/4);
    view.setLayoutParams(para);