layout - Android set ImageView's width as a ratio of another element (given the id) -
i have imageview:
<imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pbc" android:layout_below="@id/ryc"/>
is possible set it's width percentage of of element of id "@id/ryc" i've done in android:layout_below ?if so, how?
thanks
you need set width in activity, following code (just change yourpercentage
percentage want)(i have added id imageview, can change it):
xml:
<imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pbc" android:id="@+id/pbcimageview" android:layout_below="@id/ryc"/>
activity:
float perc = yourpercentage / 100; imageview imgview = (imageview) findviewbyid(r.id.ryc); imageview pbcimageview = (imageview) findviewbyid(r.id.pbcimageview); pbcimageview.setwidth(imgview.getwidth() * perc)
hope helps!
Comments
Post a Comment