简体   繁体   中英

Is there a way for Android Layouts to within an activity, to reset dimensions to Layouts/ImageView?

when i start an activity, it populates the screen with an ImageView that is fill_parent, so the view will populate the screen with my example, gives the X and Y values of 600 and 940 respectively.

When i change the orientation of the screen, getting the height and width seems to be returning the same values.

Can I have it so when i rotate, it adjusts the ImageViews dimensions?

I was looking at onConfigurationChanged() to where i put the code, but when i was using

 DisplayMetrics dm = new DisplayMetrics();
 getManager().getDefaultDisplay().getMetrics(dm);

it would return the full screen size and not the applicable canvas to work with.

How would i make the ImageView resize itself correctly.

Relevent XML data:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/imageViewer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix"
        android:src="@drawable/accept" />
</LinearLayout>

Edit: I could reload the activity on orientation change and perserve data through saved instance..... that would accomplish it if i am thinking correctly, but i dont want to restart the activity as i dont really think it is needed to.

You could use OrientationEventListener for this, and set Image height and width you want to in the handler for orientation event, for example, you could extend OrientationEventListener, then use:

public abstract void onOrientationChanged (int orientation)

Note: The previous method is called when the orientation of the device has changed. orientation parameter is in degrees, ranging from 0 to 359. orientation is 0 degrees when the device is oriented in its natural position, 90 degrees when its left side is at the top, 180 degrees when it is upside down, and 270 degrees when its right side is to the top. ORIENTATION_UNKNOWN is returned when the device is close to flat and the orientation cannot be determined.

In there you could edit the ImageView Height and Width. Good Luck:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM