how to set image width height based on screen size in gridview

后端 未结 3 1869
旧时难觅i
旧时难觅i 2021-02-04 09:00

I want to show 3x3 sized gridview. I want to set the height and width based on device size. I am taking reference from this link.

MainActivity-

public cl         


        
3条回答
  •  遥遥无期
    2021-02-04 09:16

    You can get the screen dimensions like:

    final DisplayMetrics displayMetrics=getResources().getDisplayMetrics();
    final float screenWidthInDp=displayMetrics.widthPixels;
    Log.WTF("ScreenWidth", "width: "+screenWidthInDp+", menuWidth: "+screenWidthInDp/3);
    

    And for the gridview, I would suggest you to take a look at this awesome library called Staggered Grid View. And their sample here.

提交回复
热议问题