I had a problem creating a SplashScreen. The image, 512x512, imported into the drawable directory does not maintain the same ratio after the code is executed. The height is larger than the width, and adjusting manually works on one device, but on another the problem remains.
SplashActivity class:
public class SplashScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
ImageView logo = (ImageView) findViewById(R.id.imgLogo);
logo.setBackgroundResource(R.drawable.robot);
Animation anim = AnimationUtils.loadAnimation(this, R.anim.move_up);
logo.setAnimation(anim);
//Handler: Aplica as mudanças de interface da SplashScreen
try {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(intent);
SplashScreenActivity.this.finish();
}
}, 4000);
} catch(Exception e){}
}
public void onBackPressed(){
this.finish();
super.onBackPressed();
}
}
xml da activity:
<?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"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/colorPrimaryDark">
<TextView
android:text="@string/inicializando"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inicioTexto"
android:textSize="25sp"
android:layout_marginBottom="170dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="#ffffff"/>
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="90dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="315dp"
app:srcCompat="@drawable/robot"
android:id="@+id/imgLogo"
android:layout_above="@+id/inicioTexto"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
AndroidManifest
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreenActivity"
android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Nova MainActivity criada -->
<activity android:name=".MainActivity"></activity>
</application>
I should note that in the preview of xml the image is in its correct proportion, only in compilation does the error occur.
Note: I do not think it's necessary, but I'll provide the animation code for the image:
<?xml version="1.0" encoding="utf-8"?>
<translate
android:duration="900"
android:fromYDelta="-2000"
android:toYDelta="0"
/>