I am loading an animation into an image view and loading the AnimationDrawable like so:
Activity call
AnimationDrawable animationDrawable =
(AnimationDrawable) ContextCompat.getDrawable(mContext, R.drawable.my_animation);
mAnimationImageView.setBackground(animationDrawable);
my_animation.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="#drawable/my_animation_00" android:duration="#integer/100" />
...
<item android:drawable="#drawable/my_animation_10" android:duration="#integer/100" />
</animation-list>
The oneshot is read and applied on my test devices except for the Nexus 5x that is running Marshmallow. On that device the animation repeats indefinitely. Since one shot is false by default in the AnimationState I'm guessing it's not being read.
I can set the one shot in code to fix it:
mAnimationDrawable.setOneShot(true);
Is this happening to anyone else?
There doesn't seem to really be any bug here. This might have been an artifact of running Android Studio 2.0 Preview 7. The code is working fine now.
Uh, we had a slight ide malfunction, but uh... everything's perfectly all right now. We're fine. We're all fine here now, thank you. How are you?
Related
I want to make a Activity of browsing pictures which likes the WeChat in Chatting Activity by shared element.
But I found that. Using the same code , the animation is very smooth in the my first phone(Android 6.0). And in the second phone(Android 8.0), the animation has a little unsmooth.
Have you ever encountered such a situation? Do you know the reason? Any Solutions?
I found in my demo, if your activity is as follows
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.changebounds_with_test))
And your transition is as follows
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
<changeBounds/>
<changeImageTransform/>
<changeClipBounds/>
<changeTransform/>
</transitionSet>
The point is the duration which is greater than 300ms(default duration). Then the animation of Shared Element is unsmooth in Oreo.
But I had not set SharedElementEnterTransition in my project, the animation is also unsmooth in Oreo.
I think my project has any logic of code that influence the animation, which leads to the duration greater than 300ms.
Now I don't use shared element, and use value animation to make transition animation.
We have a TextView containing a drawable-left and drawable-right from app resources. On some devices like
Sony Xperia L running Android 4.1.2,
Samsung Galaxy Young or
Samsung Galaxy SII
we are facing a strange problem. The drawable will be shown translucent/transparent. On other devices like
Samsung Galaxy S4 (4.4.2) or
HTC ONE V (4.0.3)
the drawable will be shown correctly.
This is a cutout of the Layout definition:
<TextView
android:id="#+id/button_current_warnings"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="3dp"
android:gravity="center_vertical"
android:background="#drawable/selector_classic_list_item"
android:layout_gravity="center_vertical"
android:drawablePadding="8dp"
android:drawableLeft="#drawable/ic_classic_current_warning_white"
android:drawableRight="#drawable/ic_classic_row_arrow"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:maxLines="2"
android:ellipsize="end"
android:text="#string/current_warnings"
android:textSize="?attr/warningGermanyBoxTextSize"
android:textColor="?attr/itemFavoriteTitleTextColor"/>
On the HTC One V device this layout looks pretty nice:
On the Sony Xperia L the layout is broken, due to the transparency of the imageview drawables. Both drawables are only shown a little bit:
Furthermore, if we change the drawable to a different one the result is nice on both devices:
HTC:
Sony:
Additionally I attached the two drawables used for my current tests (they are both white-colored, because of this you will not see anything here):
Wrong displayed drawable:
Correct displayed drawable:
Does anyone face the same problem or has any hints for us?
Update: In my code, I only set an ClickListener on this TextView:
buttonGermany = returnView.findViewById(R.id.button_current_warnings);
buttonGermany.setVisibility(View.VISIBLE);
buttonGermany.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Do something
}
});
I only encountered this problem on Android 4.1.2 (Jelly Bean) devices. The problem with the translucent presentation of the icons has something to do with caching of drawables in 4.1.2. In my case, I used the wrong ic_classic_current_warning_white-drawable in a drawable-selector, too:
<selector xmlns:android="schemas.android.com/apk/res/android"; android:exitFadeDuration="#android:integer/config_mediumAnimTime">
<item android:state_pressed="false" android:state_focused="true" android:drawable="#drawable/ic_classic_current_warning_white"/>
<item android:state_pressed="true" android:drawable="#drawable/ic_classic_current_warning_white"/>
<item android:drawable="#drawable/ic_classic_current_warning_black"/>
</selector>
This selector was used on a button in previous activity. If I touched this button, the above view appears. By using the android:exitFadeDuration the ic_classic_current_warning_white-drawable was faded out after touching my button. But it seems to be that the drawable cache holds a reference to ic_classic_current_warning_white-drawable with an alpha-value lower than 100%, when the new activity was opened. If I used this drawable again in next view, it was not displayed with 100% alpha, but with the alpha-value when leaving the previous activity.
My current solution is simply to duplicate the drawable ic_classic_current_warning_white. One will be used for the selector. The other copy will be used for "static" purposes.
I have a very basic widget with two buttons in a layout. They look like standard android buttons, but with the 4.4 update the buttons now appear as a dark grey instead of light grey. They remain normal in previous versions of android. Does anyone have any idea of why this is happening and how I can fix this?
Thanks!
Button xml:
<Button
android:id="#+id/button_widget_newshift"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/new_shift_split"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#101010"
android:textSize="#dimen/widget_text" />
I don't have an answer (and I don't have enough of a reputation to post a comment). I have the same problem, although I'm creating my buttons in code. They work on devices prior to 4.4, but are dark grey and borderless on my Nexus with 4.4 and a 4.4 emulator.
I understand that 4.4 changed drawables to tone down touch feedback (see http://developer.android.com/design/patterns/new.html). Perhaps, in the process, a button style or drawable got misplaced. If so, a solution/kludge might be to copy working resources from the SDK into your project and call setBackgroundResource() to them. I haven't tried this; I'm hoping someone can come up with something more elegant and definitive.
In my project there are two WebViews and I am switching these WebViews alternatively to get a smooth animation while loading my url. When I am using Webview.loadUrl() method, it works fine in all devices. But when I am using the same code with loadDataWithBaseUrl() then its not working in 4.0.3 but it's working fine in 2.2, 2.3, 4.0.4, 4.1 devices.
Is this a bug jumping from WebKit?
I tried so many ways to get this done but no way out. I am really frustrated and messed-up with this.
It will be so helpful if someone could show me a right way to get this done.
You can try to add these property with webview-
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
and can use animation because its working well for me like-
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:interpolator="#android:anim/cycle_interpolator"
android:fromXDelta="100%p" android:toXDelta="0" android:duration="1000"/>
</set>
There appears to be a bug with 4.0.3 altogether with WebView animations.
What fixed it for me was removing alpha from animation.
Basic translate animation is behaving correctly.
i'm dealing with resources issue for a while and i cannot figure it out. The thing is that my resources(shapes, gradients, layouts) don't load up in application like they should. For instance:
My "layout.xml" file (main layout for activity)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/favourite_rest"
android:orientation="vertical"
android:layout_width="fill_parent"
android:background="#drawable/activ_favourite_bck"
android:layout_height="wrap_content"
android:layout_weight="1">
...
And layout for background: "activ_favourite_bck.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#55555555"
android:centerColor="#77777777"
android:centerY="0.5"
android:endColor="#55555555"
android:angle="270" />
</shape>
In this case when i run my application, brackground is pure black like no background is set, but when i rename the file with background definition from activ_favourite_bck.xml to "halabala.xml" ( with changing reference in main layout android:background="#drawable/halabala") the background is there and everything is working fine. I want to name my resources with purpuse so later when i have more of them there is no mess. I know there is naming convention that resource filename can contain only small characters with "_" and that's what i'm fallowing.
Note: the file is recognized by IDE, there are no errors during building and i can reference file from code.
I'm woring with android 1.6 api, but i tried changing to 2.0, 2.2.. with no success. I also tried various phone types and emulator and i tried changing IDE from eclipse to IDEA and nothing helps. I tried rebuilding project, refreshing everything that can be refreshed:) i tried to wipe the application from devices with no effect. Is anybody facing similar issue like me?
Btw. the same thing is going on when i put some picture(png) in drawable folder and i'm referencing it from xml. Some pictures are recognized (and shown in running application) and some not( they are recognized only after renaming to sometning else).
Try adding an arbitrary image called a.png or some such (so it sorts alpha above your real drawable) ...
After couple of hours i worked this out. I probaly accidentally removed folder drawable-mdpi. After creating it and copying images there everything works just fine.