Javier Moreno
Javier Moreno

Reputation: 1

Android: Adding a view. Different screen size and densities

I´m trying to add a ImageView (a symbol) each time the user touch on a Imageview (A car picture) in order to let the user indicate where the car has a damage. Then I send the points to a remote server so I can get the points when the acitivity is opened again. It works properly in the specific device that set the points, but if you get the points using another device whith different screen size and resolution, obviously, the symbols are not OK. Is there any way to scale points and ImageView in order to make it possible? I mean, how could I make that, if you indicate there is a damage in the front/left door of the car, the symbol was always there when running the app in different screen sizes?

Code I´m using:

@Override
        public boolean onTouch(View v, final MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN){
                final RelativeLayout urLayoutId=(RelativeLayout)    findViewById(R.id.RelativeCoche);
                final ImageView imv=new ImageView(MainActivity.this);
                    imv.setImageResource(R.drawable.info);
        RelativeLayout.LayoutParams params = new   RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                    params.setMargins(Math.round(event.getX()),
                    Math.round(event.getY()), 0, 0); 
                    imv.setLayoutParams(params);
                return true;
             }
    });

Upvotes: 0

Views: 125

Answers (1)

Emmanuel
Emmanuel

Reputation: 13223

If I understand your question correctly, what you want to do is to include different images with the proper densities in the corresponding drawable-xxxx folder. Look at the last section of this link for more information.

Upvotes: 1

Related Questions