Condividi tramite


View.SetCameraDistance(Single) Method

Definition

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view.

[Android.Runtime.Register("setCameraDistance", "(F)V", "GetSetCameraDistance_FHandler")]
public virtual void SetCameraDistance (float distance);
[<Android.Runtime.Register("setCameraDistance", "(F)V", "GetSetCameraDistance_FHandler")>]
abstract member SetCameraDistance : single -> unit
override this.SetCameraDistance : single -> unit

Parameters

distance
Single

The distance in "depth pixels", if negative the opposite value is used

Attributes

Remarks

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.

The distance of the camera from the view plane can have an affect on the perspective distortion of the view when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)

The distance is expressed in "depth pixels." The default distance depends on the screen density. For instance, on a medium density display, the default distance is 1280. On a high density display, the default distance is 1920.

If you want to specify a distance that leads to visually consistent results across various densities, use the following formula:

float scale = context.getResources().getDisplayMetrics().density;
            view.setCameraDistance(distance * scale);

The density scale factor of a high density display is 1.5, and 1920 = 1280 * 1.5.

Java documentation for android.view.View.setCameraDistance(float).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also