简体   繁体   English

在android中将图像部分移出屏幕

[英]move a image partially out of the screen in android

I have an ImageView in android. 我在android中有一个ImageView I want to move the image partially inside the screen such that only a part of the image is visible. 我想在屏幕内部分移动图像,使得只有部分图像可见。 If I set margin or padding in xml the image shrinks. 如果我在xml中设置边距或填充,图像会缩小。 I used a translate Animation in onCreate method. 我在onCreate方法中使用了translate Animation But I see image moving the first time the view is presented. 但是我看到第一次出现视图时图像会移动。 I want the image to be partially visible without the shift being visible. 我希望图像部分可见,而不会看到移位。 Is there any way of doing this? 有没有办法做到这一点?

in the parent view (like LinearView ) set ClipChildrens=false , if what you are looking for 在父视图中(如LinearView )设置ClipChildrens=false ,如果您正在寻找

check this code, it works for me... 检查这段代码,它对我有用......

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="-20dp"
        android:src="@drawable/ic_launcher" />

</FrameLayout>

I found that if you use negative margins, then you can't alignParent on the opposite side, so, let's say you're trying to have the image half off on the right side of the view, you can't specify android:layout_alignParentLeft. 我发现如果你使用负边距,那么你就不能在对面使用alignParent,所以,假设你试图让图像在视图的右侧半截,你不能指定android:layout_alignParentLeft 。 Also, if you need the full image and don't want it to be clipped, like in the case you wanted to animate on full screen onClick, you have to set the parent layout android:clipChildren="false". 此外,如果您需要完整的图像并且不希望它被剪裁,就像您希望在全屏幕上点击动画一样,您必须设置父布局android:clipChildren =“false”。 The following xml def works for me: 以下xml def适用于我:

<ImageView
        android:id="@+id/you_feature_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="@dimen/feature_margin_right"
        android:contentDescription="feature_image"
        android:gravity="center_vertical"
        android:padding="@dimen/zero"
        android:paddingBottom="@dimen/zero"
        android:paddingLeft="@dimen/zero"
        android:paddingRight="@dimen/zero"
        android:paddingTop="@dimen/zero"
        android:src="@drawable/feature_phone_02_2x" />

I'm posting this now because I just burned a few hours trying to figure this out myself, and thought maybe it'd help somebody else in the future should they come across this question like I did. 我现在正在张贴这个,因为我只是烧了几个小时试图自己解决这个问题,并认为如果他们像我一样遇到这个问题,它可能会帮助其他人。

How about this. 这个怎么样。

In your Activity's onCreate: 在您的Activity的onCreate中:

ImageView yourImage = (ImageView)findViewById(R.id.your_image_control_id);
yourImage.setX(1000);
yourImage.setY(1000);

That way, it is positioned properly at startup. 这样,它在启动时正确定位。 Or you could use an AbsoluteLayout and set the image's x and y coordinates that way. 或者您可以使用AbsoluteLayout并以此方式设置图像的x和y坐标。 Make sure you arent using fill_parent for either the height or width. 确保您没有使用fill_parent作为高度或宽度。

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

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