Inflated ImageView to put in GalleryView isn't the right size

前端 未结 2 1281
挽巷
挽巷 2020-12-10 14:15

I am trying to inflate an ImageView that scales a Drawable that I can display in a GalleryView. My code to inflate the view seems to work fine, except that the attributes o

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 14:49

    The trick is simply to use the following version of inflate():

    inflater.inflate(R.layout.gallery_item, parent, false);
    

    The last two parameters are mandatory. If you pass "null" as the parent, the inflater does not know what type of layout parameters to create and therefore ignores all the android:layout_ XML attributes. The last parameter simply tells the inflater to not add the inflated view to the parent right away. If you pass true (at least inside an Adapter's getView() method), bad things will happen.

提交回复
热议问题