Frame by frame animation problems with Gingerbread 2.3.6 - android

Objective:
Frame by frame animation on an ImageButton without the user having to "click" it, all through xml as well. This has already been accomplished, but it won´t work for Android 2.3.6, and I can´t for the life of me, figure out why.
Set up:
The project is clean, there´s nothing else but a main activity and an ImageButton within that main activity.
Main activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageButton
android:id="#+id/main_tree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:contentDescription="#string/main_tree"
android:background="#00000000"
android:soundEffectsEnabled="true"
android:padding="30dp"
android:src="#drawable/growing_tree" />
</RelativeLayout>
As you can see, the ImageButton points to the drawable growing_tree, an xml SELECTOR.
growing_tree
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/anim_growing_tree"
android:state_enabled="true" />
</selector>
And this one in turn points to the actual frame by frame animation.
anim_growing_tree
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/tree1" android:duration="150" />
<item android:drawable="#drawable/tree2" android:duration="150"/>
<item android:drawable="#drawable/tree3" android:duration="150"/>
<item android:drawable="#drawable/tree4" android:duration="150"/>
<item android:drawable="#drawable/tree5" android:duration="150"/>
<item android:drawable="#drawable/tree6" android:duration="150"/>
<item android:drawable="#drawable/tree7" android:duration="150"/>
<item android:drawable="#drawable/tree8" android:duration="150"/>
<item android:drawable="#drawable/tree9" android:duration="150" />
<item android:drawable="#drawable/tree10" android:duration="150" />
<item android:drawable="#drawable/tree11" android:duration="150" />
<item android:drawable="#drawable/tree12" android:duration="150" />
</animation-list>
It´s all quite straight forward. Just in case I´ll add the manifest file too.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.marstudio.memorytree"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.marstudio.memorytree.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I run it with an emulator of a Nexus-S with android 4.2.2 it works fine, as soon as the screen comes on the frame by frame animation begins.
Both .xml files are under res/drawable
Now when I run it on a real device with Gingerbread 2.3.6 the screen comes on but the it stays on the first frame, the animation won´t continue. What could I be doing wrong? I´d really appreciate some input!

I just had a similar-ish problem; I tested my application on 3 different live devices and here's my conclusions.
If I declared my animation drawable to be the background of an ImageView in an XML layout file, it'd work fine on Google Nexus 4 but on HTC One and Sony Xperia Z1 it would basically show the 1st frame and not animate at all.
Yes, the OS versions on all the phones are different (HTC One hasn't got 4.4 yet, for example) but since you've had a similar problem on 2 completely different versions of Android, this leads me to believe that there's some major differences in how the code behaves under different Android flavours - i.e. you have to start the animations "properly" for them to work on all phones.
Example code snippet:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
splashImageViewAnimatedBeep = (ImageView) findViewById(R.id.splashImageBeep);
splashImageViewAnimatedBeep.setBackgroundResource(R.drawable.splash_animation_beep);
splashAnimationImageViewBeep = (AnimationDrawable) splashImageViewAnimatedBeep.getBackground();
splashAnimationImageViewBeep.start();
}

Related

Android - Display GIF At Application Start With Styles-Only Method

Currently I'm using Styles-only method and I was using WEBP formatted logo. Works fine. Now I have a GIF and I'm trying to show this GIF while my application starting.
I added this GIF to drawable folder but I have issues.
Problem is; firstly I see my new gif's first frame (I can say, motionless preview of my gif in android studio) as picture, and then I can see my gif but this picture and gif are both visible and overlapped.
My structure is in below.
start_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#color/my_dark_color" />
</shape>
</item>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/my_gif_file"
android:alpha="0.5"/>
</item>
</layer-list>
themes.xml:
<style name="AppTheme.Launch" parent="AppTheme.Dark">
<item name="android:windowBackground">#drawable/start_screen</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
AndroidManifest.xml:
<activity
android:name=".LaunchActivity"
android:configChanges="orientation|screenSize"
android:label="#string/application_name"
android:launchMode="singleTask"
android:resizeableActivity="${debug}"
android:theme="#style/AppTheme.Launch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
activity_launch.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/splash_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
LaunchActivity.kt:
class LaunchActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_launch)
Glide.with(this).asGif()
.load(R.drawable.my_gif_file)
.into(splashlogo)
...
...
...
}
}
I tried to debug the code. I realize that, the Glide... codeline is executed a few seconds after seeing first motionless picture.
What is wrong ? Can you help me to find the solution?

Xamarin Forms Android splash screen landscape orientation

I am trying to implement splash screen in portrait and landscape. Following link https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
I added two separate files SplashBackground.xml and SplashBackgroundLandscape.xml with correct images. Added values-land folder with separate style.xml. Still the landscape image is not displayed on rotation. Am I missing anything?
Below is the style.xml for landscape. Portrait is same with drawable name #drawable/splash_portrait
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:windowBackground">#drawable/splash_landscape</item>
</style>
</resources>
Please see the updated screenshot with lower case names
Code for splash_landscape.xml. It has correct image name - splash_bg_landscape
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/colorPrimary" />
</item>
<item>
<bitmap android:src="#drawable/splash_bg_landscape" android:tileMode="disabled" android:gravity="center" />
</item>
Code for style.xml from values-land folder (for landscape mode)
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:windowBackground">#drawable/splash_landscape</item>
</style>
I feel everything is correct; however, when I deploy the app in landscape mode, it is not using the correct splash_bg_landscape image. App shows stretched portrait image. I am using Samsung device for testing.
I noticed that the item name "splash_landscape" is not same with "splashbackgroundlandscape",you may want to change that.
And below is my test sample solution structure you can take a look:
style(land):
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.companyname.myandroidtestapp">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:allowBackup="true" android:theme="#style/MyTheme" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:roundIcon="#mipmap/ic_launcher_round" android:supportsRtl="true" >
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

Splash screen is sometimes distorted and blurred

I have a splash screen activity with the following theme:
<style name="AppTheme.Launcher" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#drawable/splash_theme</item>
</style>
Here is a part of my manifest:
<activity
android:name=".activities.SplashActivity"
android:theme="#style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And here is my drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorPrimaryDarkBackground" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/shelpwelt_theme" />
</item>
</layer-list>
At some builds all works perfectly but sometimes the splash screen is completely distorted and blurred but just at the first 2-3 seconds. Then when my splash screen activity reaches onCreate the theme looks perfectly fine.
Here is the problem:
You are using a gif file for this case. And after the given time you said, 2-3 sec it wraps the screen size, so the image gets bigger. That's why it get's blurred on the screen.
Add bottom,left,right,top size to your item.
Change your drawble file to this :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorPrimaryDarkBackground" />
<item
android:bottom="24dp"
android:left="24dp"
android:right="24dp"
android:top="24dp"
>
<bitmap
android:gravity="center"
android:src="#drawable/shelpwelt_theme" />
</item>
</layer-list>
It might be a scaling issue, try to change splash's layout, instead of designing the entire image and set it as a background, design your layout to have two images one for the gray rectangle and the other for the video icon

Android windowBackground in theme not working - Splashscreen

I'm trying to add splash-screen to my Android app.
I've been following instructions from here. It's the standard way as I get it, and it seems logical.
So it's really simple right? Create drawable resource, use it in a theme as windowBackground, use the theme? Well it doesn't work for me...
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="euroicc.sicc">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme.Splashscreen">
<activity android:name="euroicc.sicc.ui.MainActivity"
android:theme="#style/AppTheme.Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
styles:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:spinnerDropDownItemStyle">#style/mySpinnerItemStyle</item>
<item name="android:itemBackground">#color/main_background</item>
<item name="android:textColor">#color/text_default</item>
<!--<item name="android:popupMenuStyle">#style/MyAlertDialog</item>-->
</style>
<style name="AppTheme.Splashscreen" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">#drawable/splashscreen_drawable</item>
</style>
</resources>
splashscreen_drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_green_light"></solid>
</shape>
</item>
<item>
<bitmap android:src="#drawable/splashschreen_eicc"
android:gravity="center"></bitmap>
</item>
</layer-list>
I've tried other codes from other sites, but nothing seems to work.
Only white background is displayed for less then a second (approximately), and then the app starts running. I'm setting the theme AppTheme in onCreate method of main activity so it uses it's default theme always except on start.
I'm also overriding onPause and onResume, but I call their supers, so that shouldn't be a problem.
I'm testing on v7.0.0, but that shouldn't be a problem also?
I have more styles but I removed them from the example code, because they are used for dialogs and elements inside xml files, not for activities.
So what is the problem and how do I solve it? When I first read about splashscreens I thought setting windowBackground would've been enough
You don't set your background in styles.xml, rather inside your splashcreen layout xml file. Here is my layout example:
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription"
android:background="#drawable/green" ==============================> HERE!
tools:context=".activity_splash_screen">
<ImageView
android:id="#+id/logo"
android:layout_width="#dimen/_150sdp"
android:layout_height="#dimen/_150sdp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/_100sdp"
android:src="#drawable/white_logo"
/>
<ImageView
android:id="#+id/title"
android:layout_width="#dimen/_240sdp"
android:layout_height="#dimen/_150sdp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/_100sdp"
android:src="#drawable/title"
/>
If you need help with the entire code, I can help you!
I've had this problem. I created the splash screen as a layer-list drawable, and in the theme as windowBackground as it is recommended everywhere, yet it wouldn't work on some devices (like my and my friend's Motorolas, a few other phones) - a black screen would be shown. For me the solution was to wrap my splash activity code in a Handler's postDelayed runnable with some small delay:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Handler(Looper.getMainLooper()).postDelayed( { //this is a trick so the splash screen - in window bg theme - is displayed on all devices, instead of black screen. E.g. moto g6
val startMainActivityIntent = ...
startActivity(startMainActivityIntent)
finish()
}, 100)
}
I am not particularly fond of delaying UI, if I knew a better way that worked, I would not do this. But it’s better than black screen.

Custom Progress Bar with Animation List

I want to create a progress bar which should show moving images effect. for that I have created an animation list and have saved in my drawables folder in res. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/p_one" android:duration="150" />
<item android:drawable="#drawable/p_two" android:duration="150" />
<item android:drawable="#drawable/p_three" android:duration="150" />
<item android:drawable="#drawable/p_threesix" android:duration="150" />
</animation-list>
After that I have used this drawable like this: for my ProressBar Drawable
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateOnly="true"
android:indeterminateDrawable="#drawable/progress_bar_anim"
android:visibility="visible" />
Problem: Nothing is displaying when I run this code. Why ?
When I use any single image instead of the animation-list drawable, then it is displayed correctly. Is there any other to do this ?
Try to add android:oneshot="false" like below in <animation-list ..> attribute
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
...
</animation-list>
android:oneshot="false" is
Boolean. "true" if you want to perform the animation once; "false" to loop the animation.
Android developer link for Frame animation
Similar strange problems here, I tried two different device, A worked very well, B showed two images in horizontal, I add <clip> in <item> , A became not working, B worked very well, so...better not to use <animation-list> in progressBar...

Categories

Resources