Home  >  Q&A  >  body text

android - 用LayoutParams动态设置高度,在不同手机上显示效果不一样

比如LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,440);我这样设置后在我的手机上显示的是完整的,在别的手机上显示不完整。
我也使用了网上搜到的方法:int screenHeight=getWindowManager().getDefaultDisplay().getHeight();
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,(int)(0.3*screenHeight));这个又没法算准百分比,真纳闷

黄舟黄舟2763 days ago802

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:41:34

    Please use the tool class to convert dpi to px first and then set it up

    reply
    0
  • Cancelreply