android - Anchor ImageView position to another ImageView which is being scaled -


i got layout:

    <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"   android:id="@+id/rel2"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:background="#ffffff" >    <imageview     android:id="@+id/tree"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerhorizontal="true"     android:layout_centervertical="true"     android:src="@drawable/lemon_large"     android:scaletype="centercrop"     />   <imageview        android:id="@+id/fruit"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:src="@drawable/lemonpiece"       android:layout_alignleft="@+id/tree"       android:layout_aligntop="@+id/tree"       android:layout_marginleft="95dp"       android:layout_margintop="136dp"/> 

the tree being scaled, top , bottom cropped. because of screens variability in height. wanna do, have fixed image view, in same place relative image view no matter how being scaled.

ive tried different scaletype values, scales image , on every screen image somewhere else relative "tree".

another possibility tried align top of screen (alignparenttop, alignparentleft, scaletype="matrix") wont work since screens short , picture wont fit screen properly. in other words, need preserve scalability , anchor top images.

any ideas?

create resource xml file dimensions, , put following,

image_dimens.xml:

<dimen name="myvaluex">95dp</dimen> <dimen name="myvaluey">136dp</dimen> 

in activity displaying imageviews:

    int myvaluex = (int) getresources().getdimension(r.dimen.myvaluex);     int myvaluex = (int) getresources().getdimension(r.dimen.myvaluex);      imageview ivfruit = (imageview) findviewbyid(r.id.fruit);     imageview ivtree = (imageview) findviewbyid(r.id.tree);     ivfruit.setx(ivtree.getx() + myvaluex);     ivfruit.sety(ivtree.gety() + myvaluey); 

hope helps, happy coding!


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -