Adding android:layoutAnimation to a LinearLayout causes FC - android-animation

I have the following XML in menu.xml, it's a LinearLayout that I need to animate, so I use the layoutAnimation property. Without this property the layout shows flawlesly, but with this property set I get a nasty forceclose and I don't understand why:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bkgrnd"
android:layoutAnimation="#anim/menu_anim" <=== adding this results in FC
...etc...
anim/menu_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500">
</alpha>
</set>
Help please! Thanks!

You cant add an animation directly to a layout. you have to create one more xml file in your anim folder which points to the animation xml (menu_anim) as below.
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="30%"
android:animation="#anim/menu_anim"
/>
lets call the above xml as anim_controller.xml
now in your linear layout use
android:layoutAnimation="#anim/anim_controller"

Related

emre1512 Noty RelativeLayout creation in Kotlin

I have a simple MainActivity with a simple main layout like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
... />
</androidx.constraintlayout.widget.ConstraintLayout>
I need to activate Noty on this activity. What I need to know is how to create RelativeLayout "yourLayout" in its simple exmple in Kotlin.
Noty.init(YourActivity.this, "Your warning message", yourLayout, Noty.WarningStyle.SIMPLE).show();
Thank you!
Add an android:id attribute to your ConstraintLayout tag:
android:id="#+id/root"
Now you can fetch a reference to that ConstraintLayout in code:
val root: ConstraintLayout = findViewById(R.id.root)
Noty.init(this#MainActivity, "Your warning message", root, Noty.WarningStyle.SIMPLE).show()

why RecyclerView doesn't work in android 9

Although everything works well in android 8 and lower, but my RecyclerView doesn't load anything in android 9.
because I used Picasso in my recyclerView Adapter, I added code bellow to my AndroidManifest but nothing changed:
android:usesCleartextTraffic="true"
this is my RecyclerView XML code which is located in a MotionLayout:
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F6F6F6"
android:elevation="10dp"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_challenge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
note that I have two recyclerView in my layout, the first one, works well
but the second one doesn't work!
Define a xml file, then add to your manifest
->> android:networkSecurityConfig="#xml/network_security_config"
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">secure.example.com</domain>
</domain-config>
</network-security-config>

Use generics in databinding's xml

<layout 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"
tools:context="com.ihu.intelligentmedicinechest.activity.MainActivity">
<data>
<variable
name="items"
type="java.util.Collection<? extends com.ihu.intelligentmedicinechest.adapter.binder.ItemBinder>"/>
</data>
</layout>
Use generics in data binding XML is wrong. Follow is the exception:
android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:cannot find type argument for ?extendscom.tvvbbb.adapter.binder.ItemBinder in java.util.Collection
loc:56:30 - 56:34
****\ data binding error ****
How can I process it?

Gradle flavors, applicationId and not resolved custom view attributes

I have a custom view based on GridLayout:
package com.mycompany.myapp;
...
public class GridLayoutForceSizeCells extends GridLayout
{
}
I have defined an xml with custom attributes for this class:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<declare-styleable name="GridLayoutForceSizeCells">
<attr name="totalImages" format="integer" />
<attr name="desiredColumnCount" format="integer" />
<attr name="spacing" format="dimension" />
<attr name="autoGenerate" format="boolean" />
</declare-styleable>
</resources>
Then, I have a layout using this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mycompany.myapp.GridLayoutForceSizeCells
xmlns:grid="http://schemas.android.com/apk/res/com.mycompany.myapp"
android:padding="3dp"
android:id="#+id/cellsGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
grid:desiredColumnCount="20"
grid:totalImages="0"
grid:spacing="1dp"
android:orientation="horizontal"/>
</LinearLayout>
The problem I am encountering is that when I change applicationId through a gradle flavor custom attributes are not resolved. I have read in gradlew help that the application package is the one used for R when it is decoupled using gradlew applicationId entry. So, applicationId should not affect my custom attributes package. But when I set applicationId to anything different from com.mycompany.myapp an error arises claiming that attributes can't be resolved.
Has anybody found a solution to this?
Cheers.
Finally fix it using xmlns:grid="http://schemas.android.com/apk/res-auto" to let it resolve the package for me in the layout file instead of the full package name.

android animator - scale view to the center (Froyo)

I have a View in my android app which I want to scale & fade away to the center of it. So far I have the following
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="1500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0"
android:toYScale="0" />
<alpha
android:duration="1500"
android:fromAlpha="1"
android:toAlpha="0" />
</set>
yet that leads to the unwanted effect the text is "scaled away" to the upper left corner. How can I correct this so it is scaling to the center of the view? I need this for API >=8 .
Thanks for any hint.
Martin
Found the solution myself, pivotX and pivotY are doing the trick
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="1500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0" />
<alpha
android:duration="1500"
android:fromAlpha="1"
android:toAlpha="0" />
</set>