android - Override onMeasure after getting ImageView by Id -
i need find view id , override onmeasure
method. know how that?
the following not work in java, conceptually it's need:
imageview myimage = (imageview) findviewbyid(r.id.some_pic); myimage.onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, heightmeasurespec); int width = measurespec.getsize(widthmeasurespec); int height = measurespec.getsize(heightmeasurespec); showother(width, height); }; myimage.setimagebitmap(bmp);
java offers this
imageview myimage = new imageview(this) { @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, heightmeasurespec); int width = measurespec.getsize(widthmeasurespec); int height = measurespec.getsize(heightmeasurespec); showother(width, height); } };
or this
imageview myimage. = (imageview) findviewbyid(r.id.some_pic); myimage.setimagebitmap(bmp);
i thought of using setonmeasurelistener
no such method defined imageview. thoughts on how going?
i'm guessing some_pic imageview declared in xml , inflated, calling setcontentview in activity class. inflation means android reads xml , translates java objects. once call setcontentview, objects instantiated, , after it's late make changes classes, such overriding imageview's onmeasure method.
i can think of 2 options:
(preferred) create new class extends imageview , overrides onmeasure. when declare some_pic in xml, instead of using imageview tag, name tag after new class (fully qualified name):
<com.mycompany.myproject.myimageview
android:id="@+id/some_pic"
...
/>don't declare some_pic in xml. in activity's oncreate method, after call setcontentview, instantiate new imageview , override onmeasure method, did in question's first java option. you'll have manually insert imageview layout; use google learn how insert view view (here's example).
Comments
Post a Comment