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:

  1. (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"
        ...
    />

  2. 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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -