小编use*_*240的帖子

如何获得真正的屏幕高度和宽度?

DisplayMetrics metrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenWidth = metrics.widthPixels;
screenHeight = metrics.heightPixels;
Run Code Online (Sandbox Code Playgroud)

我使用这些代码来获取屏幕的高度和宽度

我的Nexus7的屏幕高度应为1280

但它返回1205 ...

我的minSdkVersion是8级

所以我不能使用这些方法:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screen_width = size.x;
int screen_height = size.y;
Run Code Online (Sandbox Code Playgroud)

现在,我应该如何获得正确的屏幕尺寸?

编辑:

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 …
Run Code Online (Sandbox Code Playgroud)

android

40
推荐指数
3
解决办法
4万
查看次数

Google Map V2如何设置ZoomToSpan?

作为标题,我可以使用地图v1

mapController.zoomToSpan(..., ..., ...);
Run Code Online (Sandbox Code Playgroud)

在屏幕上包含所有标记.

剂量图V2有相同的方法吗?


2013/2/22编辑:

首先,获取您想要在屏幕上涉及的所有LatLng点.

假设您有3个LatLng点,请使用

LatLngBounds bounds = new LatLngBounds.Builder().include(point1)
                    .include(point2).include(point3).build();

mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
Run Code Online (Sandbox Code Playgroud)

android

15
推荐指数
1
解决办法
2902
查看次数

如何将膨胀的视图转换为位图?

我有一个View从布局中膨胀:

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View tagView = inflater.inflate(R.layout.activity_main, null);
TextView name = (TextView) tagView.findViewById(R.id.textView1);
name.setText("hello");
Run Code Online (Sandbox Code Playgroud)

现在我想将膨胀的视图转换为Bitmap

我应该怎么做?

android

4
推荐指数
1
解决办法
2097
查看次数

Android HttpClient:NetworkOnMainThreadException

我在下面有一些代码:

protected void testConnection(String url) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    ResponseHandler<String> responsehandler = new BasicResponseHandler();

    try {
        String connection = httpclient.execute(httpget, responsehandler);
        Toast.makeText(getBaseContext(), R.string.connection_succeed, Toast.LENGTH_SHORT).show();
        view_result.setText(connection);
    } catch(IOException e) {
        Toast.makeText(getBaseContext(), R.string.connection_failed, Toast.LENGTH_SHORT).show();
    }
    httpclient.getConnectionManager().shutdown();
}
Run Code Online (Sandbox Code Playgroud)

并在Menifest中添加权限:

<uses-permission android:name="android.permission.INTERNET"/>
Run Code Online (Sandbox Code Playgroud)

但它有一个例外:NetworkOnMainThreadException,我该怎么办?

android networkonmainthread

3
推荐指数
1
解决办法
8014
查看次数

标签 统计

android ×4

networkonmainthread ×1