android-studio - Android studio运行程序白屏,程序没问题的,怎么回事?
PHP中文网
PHP中文网 2017-04-17 15:30:16
0
2
759

之前在这个程序反复修改,测试volley都没问题,最后这个缺白屏,什么提示也没有。程序没问题吧,我在idea上运行都正常的。怎么回事呢?

程序是这样子的:

package com.example.volleyimagedemo;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.util.LruCache;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.Volley;

public class MainActivity extends Activity {

        private RequestQueue mQueue;
        private NetworkImageView image;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                initView();
                getImage("http://e.hiphotos.baidu.com/image/pic/item/b58f8c5494eef01fd6508e15e6fe9925bd317d9e.jpg");
        }
        private void initView() {

                mQueue = Volley.newRequestQueue(getApplicationContext());
                image= (NetworkImageView) findViewById(R.id.image);
        }
        private void getImage(String url) {

                ImageLoader loader = new ImageLoader(mQueue, new BitmapCache());
                image.setDefaultImageResId(R.mipmap.ic_launcher);
                image.setErrorImageResId(R.mipmap.ic_launcher);
                image.setImageUrl(url, loader);

        }
        public class BitmapCache implements ImageLoader.ImageCache{
                private LruCache<String, Bitmap> mcCache;

                public BitmapCache() {
                        int maxSize = (int) Runtime.getRuntime().maxMemory();
                        int mySize = maxSize / 4;
                        mcCache = new LruCache<String, Bitmap>(mySize) {
                                @Override
                                protected int sizeOf(String key, Bitmap value) {
                                        return value.getByteCount();
                                }
                        };
                }
                @Override
                public Bitmap getBitmap(String s) {

                        return mcCache.get(s);
                }
                @Override
                public void putBitmap(String s, Bitmap bitmap) {
                        mcCache.put(s, bitmap);
                }
        }
}

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
</LinearLayout>

网络已开:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.volleyimagedemo">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

我尝试clean project一下,却提示:

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
洪涛

Unable to delete file: Because the file is in use, use other tools to check what process is occupying the file.

The white screen is because the background of your APP is white. Change the Color of TextView to black and try again.

迷茫

If the final clean is unsuccessful, directly clean the project's build folder. In app->build, delete it manually.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template