I am developing for two different devices and need to force pxs on one device's layoutparameter object through code when sp开发者_StackOverflow社区ecifying width and height. How do I do that?
GridView.LayoutParams glp = new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT, GridView.LayoutParams.WRAP_CONTENT);
glp.width = 80; <- need to ensure this is in px or LDPI interprets it .75 of 80
glp.height = 80;
Normally I would use setFontSize(TypedValue.COMPLEX_UNIT_PX, size) and it works. How about Layouts themselves?
You need the params to be fixed? If you want to make sure adding pixels, create dimen
resources e.g: 80px in string.xml then load in LayoutParams
new GridView.LayoutParams(pixels, pixels);
They are already pixels.
See the docs
http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#ViewGroup.LayoutParams(int, int)
精彩评论