Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use centerCrop in SplashActivity

In my SlashActivity I use only AndroidManifest and style as advised here https://www.bignerdranch.com/blog/splash-screens-the-right-way/.

And in SplashActivity I want use splash.jpg, but this picture changing to screen size.

How I can use centerCrop in my style file or are there other solutions?

My drawble:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:drawable="@color/colorMaterialWhite"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/splash" />
</item>
</layer-list>

AndroidManifest:

        <activity
        android:name=".SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

SplashActivity:

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = new Intent(this, NavigationActivity.class);
    startActivity(intent);
    finish();
 }
}

Style:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>
like image 917
Денис Климков Avatar asked Nov 27 '22 03:11

Денис Климков


1 Answers

You might want to add padding to your splash image.

Inside the item tag add android:top, android:bottom, android:right, android:left

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:drawable="@color/colorMaterialWhite"/>

<item
   android:top="200dp"
   android:bottom="200dp"
   android:left="200dp"
  android:right="200dp">
    <bitmap
        android:gravity="center"
        android:src="@drawable/splash" />
</item>
</layer-list>
like image 186
R. Zagórski Avatar answered Nov 28 '22 16:11

R. Zagórski