I have an ImageView
in and开发者_StackOverflow社区roid. 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. I used a translate Animation
in onCreate
method. 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
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>
How about this.
In your Activity's 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. Make sure you arent using fill_parent for either the height or width.
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. 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". The following xml def works for me:
<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.
精彩评论