应用程序仅在三星设备上崩溃

时间:2017-05-14 11:11:08

标签: android

我基本上有一个带有愚蠢代码的启动画面...我注意到当我在大多数Android设备上运行时,它只能在三星设备上工作(不依赖于屏幕尺寸,我在4台设备上测试过)这个错误导致崩溃...

LogCat- https://gist.github.com/anonymous/2c06feb8643dc1381db39b64e0834942

崩溃 -

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{inc.bs.ksit/inc.bs.ksit.Splash}: android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)

布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/white"
android:layout_width="match_parent" android:layout_height="match_parent">

<TextView
    android:text="@string/app_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="48dp"
    android:textSize="50sp"
    android:id="@+id/textView13"
    android:textStyle="bold"
    android:textColor="@color/colorPrimaryDark" />

<ImageView
    android:layout_width="170dp"
    android:layout_height="200dp"
    android:background="@drawable/images"
    android:layout_marginTop="50dp"
    android:id="@+id/imageView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<TextView
    android:text="Powered by BS "
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView13"
    android:layout_centerHorizontal="true"
    android:id="@+id/textView14" />
</RelativeLayout>

它适用于所有其他设备,任何想法?

启动活动

public class Splash extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 400;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Log.d("tag","splash");
        new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(Splash.this, MainActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
 }

2 个答案:

答案 0 :(得分:0)

<强>更新: 您在创建之前引用ImageView,因此我只是重新排列UI项目,如果您已为视图声明了ID,则对于前android:id="@+id/imageView",您应该删除+项目下一次引用,如果android:layout_below="@id/imageView"

,请使用android:layout_below="@+id/imageView" isntade

检查出来

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="170dp"
        android:layout_height="200dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:background="@drawable/images" />

    <TextView
        android:id="@+id/textView13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="48dp"
        android:text="@string/app_name"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="50sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView13"
        android:layout_centerHorizontal="true"
        android:text="Powered by BS " />
</RelativeLayout>

答案 1 :(得分:0)

崩溃只能归因于您当前使用的图像。必须有一些奇怪的维度。要解决此问题,您可以使用其他图像,也可以使用图像缓存库Glide

使用Glide的示例代码是

Display display = getWindowManager().getDefaultDisplay();
int height = display.getHeight();
int width = display.getWidth();
final RelativeLayout layout = (RelativeLayout) findViewById(R.id.searchCityGuide);
Glide.with(this).load(R.drawable.exploref).asBitmap().into(new SimpleTarget<Bitmap>((int) width, (int) height) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
        Drawable drawable = new BitmapDrawable(resource);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            layout.setBackground(drawable);
            }
        }
    });