简体   繁体   English

有没有一种方法可以将Android布局放入活动中,以将尺寸重置为布局/ ImageView?

[英]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. 当我开始活动时,它将使用fill_parent的ImageView填充屏幕,因此该视图将使用我的示例填充屏幕,分别给出X和Y值600和940。

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? 我可以在旋转时调整ImageViews的尺寸吗?

I was looking at onConfigurationChanged() to where i put the code, but when i was using 我在看onConfigurationChanged()到放置代码的位置,但是当我使用时

 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. 我如何使ImageView正确调整自身大小。

Relevent XML data: 释放XML数据:

<?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: 您可以为此使用OrientationEventListener,并在定位事件的处理程序中设置想要的图像高度和宽度,例如,可以扩展OrientationEventListener,然后使用:

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. 方向参数以度为单位,范围为0到359。当设备以其自然位置定向时,方向为0度,左侧为顶部时为90度,上下颠倒为180度,其左侧为270度。右侧是顶部。 ORIENTATION_UNKNOWN is returned when the device is close to flat and the orientation cannot be determined. 当设备靠近平面且无法确定方向时,将返回ORIENTATION_UNKNOWN。

In there you could edit the ImageView Height and Width. 您可以在其中编辑ImageView的高度和宽度。 Good Luck:) 祝好运:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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