Reputation: 2694
I have ImageView in layout xml like this:
<ImageView
android:id="@+id/notePointerImageView"
android:layout_width="700px"
android:layout_height="6px"
android:scaleType="fitXY"
android:src="@drawable/whiteline"
/>
And I dynamically set the width, height, and Margins in onWindowFocusChanged:
RelativeLayout.LayoutParams notePointerLayoutLP = new RelativeLayout.LayoutParams(263, 2);
notePointerLayoutLP.setMargins(0, 150, 14, 0);
notePointerImageView.setLayoutParams(notePointerLayoutLP);
notePointerImageView.requestLayout();
Since the screen width is only 240x301, the imageView has its left part off screen. But looks like that part of imageView is eliminated and the image is resized inside the screen (I used fitXY), and leaving the ImageView size to be 226x2. (226 + 14 == 240, which is the screen width)
Since I have to animate the ImageView later, I cannot accept ImageView to be clipped and resized. I really need a negative left margin. Could somebody tell me how can I do this? Or is it only a simulator problem?
Upvotes: 1
Views: 1195
Reputation: 11607
To force big image to fit inside screen or some size, you can use FrameLayout
as:
<FrameLayout
android:id="@+id/fm_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
... ...
>
<ImageView
android:id="@+id/myImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:gravity="center"
android:src="@drawable/my_image"/>
</FrameLayout>
for fit specific size, you just set the layout size for FrameLayout
.
Hope this help!
Upvotes: 1