如何防止活动布局在不同的android版本上发生变化?
我在android上设计了一个计算器,如果我在版本4上运行,那么所有的组件都安排得很好,但是当我在较低的版本(如2.3)上运行时,这种安排就会改变如何防止活动布局在不同的android版本上发生变化?,android,Android,我在android上设计了一个计算器,如果我在版本4上运行,那么所有的组件都安排得很好,但是当我在较低的版本(如2.3)上运行时,这种安排就会改变 this is how i used and it worked. Hope this helps you. 那么,如何在不同的android版本中使组件的排列保持不变呢?您必须以这样的方式来设计布局,即您只需进行一次,而不必再次更改,因为您应该根据需要使用重力:中心、中心水平、中心垂直等。如果要在顶部显示任何内容,请使用allignParentT
this is how i used and it worked.
Hope this helps you.
那么,如何在不同的android版本中使组件的排列保持不变呢?您必须以这样的方式来设计布局,即您只需进行一次,而不必再次更改,因为您应该根据需要使用重力:中心、中心水平、中心垂直等。如果要在顶部显示任何内容,请使用allignParentTop true和底部对齐ParentBottomTrue。
find the version on which your app is launched. this can be done by using this
androidOS = Build.VERSION.RELEASE;
Find the height of screen using this.
DisplayMetrics metrics = getResources().getDisplayMetrics();
heightDpi = (int) (metrics.heightPixels);
now custom your height and width...
if (androidOS.compareToIgnoreCase("4") < 0
|| heightDpi < 500) {
check.setLayoutParams(new LayoutParams(40, 33));
check.setBackgroundResource(R.drawable.listviewselecter);
this is how i used and it worked.
Hope this helps you.
您也可以设置margin,但应充分考虑是否使用,因为它可能会因不同的设备而改变。
如果您遵循此注意事项,那么您的布局应该是一个完美的布局,可以在任何设备上运行。您可以发布差异,并将layout.xml与此问题共享屏幕截图。Android有各种可绘制和布局文件夹来管理不同的屏幕分辨率。您是否使用带有默认实现的小部件,或者您是否有自定义的按钮和编辑文本
this is how i used and it worked.
Hope this helps you.