大佬教程收集整理的这篇文章主要介绍了Android:AbsoluteLayout?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public int widthRatio(double ratioIn){ Displaymetrics dm = new Displaymetrics(); //gets screen properties getWindowManager().getDefaultDisplay().getMetrics(dm); double screenWidth = dm.widthPixels; //gets screen height double ratio = screenWidth/100; //gets the ratio in terms of % int displayWidth = (int)(ratio*ratioIn); //multiplies ratio desired % of screen return displayWidth; } //method to get height or Ypos that is a one size fits all public int heightRatio(double ratioIn){ Displaymetrics dm = new Displaymetrics(); //gets screen properties getWindowManager().getDefaultDisplay().getMetrics(dm); double screenHeight = dm.heightPixels; //gets screen height double ratio = screenHeight/100; //gets the ratio in terms of % int newHeight = (int)(ratio*ratioIn); //multiplies ratio by desired % of screen return newHeight; } //sets size of any view (button,text,...) to a one size fits all screens public void setSizeByRatio(View object,int width,int height){ LayoutParams params = object.getLayoutParams(); params.width = widthRatio(width); params.height = heightRatio(height); }
所以如果我说setSizeByRatio(Button,10,25);它将@L_674_3@设置为屏幕宽度的10%,高度设置为屏幕的25%.
是否有绝对布局不起作用的手机?此布局是否会导致任何其他问题?
阅读@amiekuser提供的链接,并关注理解最佳实践的方式.一些提示是为ldpi,mdpi和hdpi文件夹创建图像,使用单位表示dpi(密度无关像素)而不是原始像素,以及如何使用模拟器在多种屏幕尺寸和密度上测试应用程序.
编辑:
要设置视图的x和y位置,必须使用LayoutParams.请参阅this question,了解如何使用LayoutParams为View设置TopMargin和LeftMargin.
以上是大佬教程为你收集整理的Android:AbsoluteLayout?全部内容,希望文章能够帮你解决Android:AbsoluteLayout?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。