Android 如果屏幕小于 400 像素,让图标消失
Android let icon disappear if screen is smaller than 400px
我正在寻找一种方法,让图标或标题 (textview) 在屏幕小于 400 像素时消失。目前我正在编写一个 android 应用程序,我想让 self-made header 在较小的屏幕上消失。
提前感谢您的帮助。
如果我答对了你的问题,
您可以执行以下操作:
在您的 onCreate
中检查用户屏幕宽度:
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int screenWidthInPix= displayMetrics.widthPixels; //Screen width in px
if(screenWidthInPix < 400){
//Remove your header, or stuff u want to remove
}
希望对您有所帮助。
如果你想在屏幕的内容中做,请使用不同的 XML 布局文件,你可以 show/hide 通过在布局文件夹中定义你想要的更小的屏幕尺寸,例如layout-320sw, layout-400sw, ...
或者更简单的方法是计算屏幕宽度然后隐藏图标。
我正在寻找一种方法,让图标或标题 (textview) 在屏幕小于 400 像素时消失。目前我正在编写一个 android 应用程序,我想让 self-made header 在较小的屏幕上消失。
提前感谢您的帮助。
如果我答对了你的问题, 您可以执行以下操作:
在您的 onCreate
中检查用户屏幕宽度:
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int screenWidthInPix= displayMetrics.widthPixels; //Screen width in px
if(screenWidthInPix < 400){
//Remove your header, or stuff u want to remove
}
希望对您有所帮助。
如果你想在屏幕的内容中做,请使用不同的 XML 布局文件,你可以 show/hide 通过在布局文件夹中定义你想要的更小的屏幕尺寸,例如layout-320sw, layout-400sw, ... 或者更简单的方法是计算屏幕宽度然后隐藏图标。