2017-05-14 39 views
0

我基本上有一個愚蠢的代碼啓動畫面...我注意到,當我在大多數Android設備上運行它,它的工作原理,但只在三星設備(不依賴於屏幕尺寸,我4臺設備測試),它造成的這個錯誤崩潰......應用程序崩潰只在三星設備

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

Crash--

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); 
    } 
} 
+0

把你的代碼,同時也完整的日誌,請 –

+0

將在這樣做幾分鐘...當我嘗試它時,一些格式化問題即將到來,所以我無法上傳 – Firewolf

+0

圖像尺寸是否太大?你有沒有嘗試在三星最新的手機上的相同的應用程序(改進硬件) – Swarnveer

回答

0

更新: 您參考,以ImageView創建它之前,所以我剛剛重新排列UI項,如果你已經宣佈對一個視圖的ID,爲前android:id="@+id/imageView"你應該在未來refrence刪除+項目,所以使用android:layout_below="@id/imageView" isntade如果android:layout_below="@+id/imageView"

檢查了這一點

<?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> 
+0

沒有,仍然崩潰 – Firewolf

+0

你應該告訴你爲什麼添加了這段代碼。 – Swarnveer

+0

@Swarnveer這裏是解釋 –

0

崩潰只能歸因於您當前使用的圖像。一定有一些奇怪的尺寸。爲了解決這個問題,你可以使用一個不同的圖像,或者您可以使用圖像緩存庫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); 
      } 
     } 
    }); 
+0

where exploref是圖片的名稱 – Swarnveer

相關問題