android - How to make a LayerImageDrawable with different types of gravity -
i trying build image view has 2 images inside of it; photo in background small indicator on top of it. however, i'm stuck in trying indicator appear in bottom-right of image, while photo in background supposed centered , scaled fit main image.
playing gravity property of various elements not seem accomplish anything.
below code tried use set gravity inside drawable, , xml element contains layerdrawable own gravity set, neither seems anything.
resources r = fragment.getactivity().getresources(); drawable[] layers = new drawable[2]; layers[0] = r.getdrawable(r.drawable.addcoverphoto); layers[1] = r.getdrawable(r.drawable.project_active); // user-content instead ((bitmapdrawable)layers[1]).setgravity(gravity.right); layerdrawable layerdrawable = new layerdrawable(layers); image.setimagedrawable(layerdrawable); <imageview android:layout_width="100dp" android:layout_height="0dp" android:id="@+id/todayphotoview" android:scaletype="center" android:layout_gravity="bottom"/>
you make overlayed image (the 1 bottom right corner) nine-patch image image located in bottom right corner of 9 patch. require making leftmost 2 pixels , topmost 2 pixels scalable part. way drawable stretch match on left , top, leaving image in bottom right corner.
if need more flexibility in solution, can use framelayout around 2 imageviews. use first imageview display photo , set layout gravity on second imageview bottom|right wrap_content layout_width & height.
Comments
Post a Comment