Issue
I don't have a 480x800 device so I am using genymotion emulator instead. The specs for Nexus-S says 480x800 but when I get the size of the screen in the app it says 480x728? I was wondering if that's something that is happening on the actual device as well or it is just a bug in genymotion emulator?
@Override
public void onClick( View view )
{
if ( view == null )
return;
View v1 = getActivity().findViewById( R.id.bg );
Toast.makeText( getActivity(), "height:" + v1.getHeight() + " width:" + v1.getWidth(), Toast.LENGTH_SHORT ).show();
}
I have these in my style.xml
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
Here is the layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
</RelativeLayout>
Solution
The difference in actual height and your view height is a height of software buttons bar at the bottom of the screen (it is 48 dp).
The correct way to determine actual screen height depends on device API version and described here: How to get real screen height and width?
use the following snippet:
int screenWidth = 0;
int screenHeight = 0;
if (Build.VERSION.SDK_INT >= 11) {
Point size = new Point();
try {
this.getWindowManager().getDefaultDisplay().getRealSize(size);
screenWidth = size.x;
screenHeight = size.y;
} catch (NoSuchMethodError e) {
Log.i("error", "it can't work");
}
} else {
DisplayMetrics metrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenWidth = metrics.widthPixels;
screenHeight = metrics.heightPixels;
}
Answered By - nemezis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.