2

I want to use an ImageView as a background watermark. I would like the image to be partially offscreen (think of it as in the bottom right corner of the screen and then pushed another 20% to the right and 10% down), but I can't figure out how to arrange my view like that. I don't need animation or anything and I would like to avoid just cropping the image because: 1) we use this same non-cropped image elsewhere and I'd rather not duplicate it and 2) I'm working with several layouts which may have different positioning of this image requiring multiple cropped copies.

I've tried several different layouts and I've tried setting the position of the ImageView in my onCreate, onStart, onResume, etc., but the width and height of all of my views are will 0 by 0. It's incredibly frustrating that something so simple should require so much work.

UPDATE: Here is the xml layout I am using... I have tried numerous variations on this, this is just what I happen to have at the moment which also doesn't work:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>


<ImageView
    android:id="@+id/watermark"
    android:src="@drawable/dollar_sign_whole"
    android:gravity="right|bottom" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginRight="-50dp"

/>
<ListView
    android:id="@+id/tableView"
    style="@style/WatermarkedTable"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:cacheColorHint="#00000000"
    android:divider="#ccc"
    android:dividerHeight="1dp"
/>
</RelativeLayout>
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
  • Not sure, but maybe `android:translationX` and `android:translationY` might help. Or maybe `android:padding`. – Joubarc Aug 17 '11 at 09:59

2 Answers2

0

Try using the attibute android:layoutMargin_Right="-50dip"

Edit: Sorry, the only way I could find to do this was to use an AbsoluteLayout and add the attributes android:layout_x="100dip" and perhaps android:layout_y="50dip". I know that the AbsoluteLayout is deprecated but I couldn't see any other way with the other layouts. There is a link here which describes offsets which are used by an animation translation - perhaps you could experiment with these to see if they can be applied to a static image.

Community
  • 1
  • 1
John J Smith
  • 11,435
  • 9
  • 53
  • 72
0

I've done this with AbsoluteLayout. I know, deprecated but the only way I could find. Set a negative -x

Rich
  • 61
  • 1