Display images on Android

Hi, I'm trying to make Hotspot on an image, but the problem is that the location of the access point for resizing the screen also has changes

I have done the following things at the moment

Bellow is my layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="myapp.imagemappingdemo.MainActivity">
<FrameLayout
    android:layout_width="7000pt"
    android:layout_height="5000pt">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/bolt_int"
        android:text="Hello World!" />
    <RelativeLayout
        android:id="@+id/upperView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        >
    </RelativeLayout>
</FrameLayout>

I use the following code to build an image.

    screenWidth = this.getResources().getDisplayMetrics().widthPixels;
    ImageView btn = new ImageView(MainActivity.this);
    RelativeLayout.LayoutParams bp = new    RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bp.leftMargin = (int) (774.6667 );
    bp.topMargin = (int) (413.25);
    btn.setLayoutParams(bp);
    btn.setImageResource(R.drawable.ic_stat_name);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "Button Click", Toast.LENGTH_LONG).show();
        }
    });
    upperview.addView(btn, bp);

I'm trying to figure out how I am going to accurately determine the position on another screen using the same (X, Y) coordinate, can someone help me with this, what is the relationship between the height and width of the screen and (X, y), regardless screen size

+4
source share
4 answers

If your next code works for a specific screen,

bp.leftMargin = (int) (774.6667 );
bp.topMargin = (int) (413.25);

, , 800 x 480 -

int standardWidth = 480;
int standardHeight = 800;
bp.leftMargin = ((int) (774.6667 ) * dm.widthPixel)/standardWidth;
bp.topMargin = ((int) (413.25) * dm.heightPixel)/standardHeight;

leftMargin topMargin .

, :)

+1

, Imageview Wrap, java ImageView,

0

X, Y % - . 100 , X 10, X = 0,1. float:

float[] values = new float[9];
btn.getImageMatrix().getValues(values)

5- . Hotspot:

float hotspotX = btn.getWidth()*X + values[2];
float hotspotY = btn.getHeight()*Y + values[5];
0

,

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
x = size.x; y = size.y;

(x / 2, y / 2), this gives a central position on the screen.

U can specify left and right edits in terms of y, like:

bp.leftMargin = 10*y/100;
bp.rightMargin = 10*y/100;

This sets your image to 10% of the left and right margins.

Hope this helps! U can make changes according to your requirements.

0
source

All Articles