0
I had a problem creating a Splashscreen. The 512x512 image imported into the drawable directory does not maintain the same ratio after running the code. The height gets larger than the width, and manually adjust 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 by 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 mention, that in the xml preview the image is in its correct proportion, only in the compilation occurs the error.
Note: I do not think it is necessary, but I will make available the code of the animation of the image:
<?xml version="1.0" encoding="utf-8"?>
<translate
android:duration="900"
android:fromYDelta="-2000"
android:toYDelta="0"
/>