Android: anim.slide_in_right Can not Find

1

I have the following code but I can not access android.R.anim.slide_in_right

package com.agmdeveloptest.testinganimations;

import android.animation.Animator;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

    Button buttonPrev, buttonNext;
    ViewSwitcher viewSwitcher;
    Animation slide_in_left, slide_out_right, lol;

    TextView  txttoAnimate;
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        buttonPrev = (Button) findViewById(R.id.prev);
        buttonNext = (Button) findViewById(R.id.next);
        viewSwitcher = (ViewSwitcher) findViewById(R.id.viewswitcher);

        lol = AnimationUtils.loadAnimation(this,
                android.R.anim.slide_in_right);
        slide_out_right = AnimationUtils.loadAnimation(this,
                android.R.anim.slide_in_right);

        viewSwitcher.setInAnimation(slide_in_left);
        viewSwitcher.setOutAnimation(slide_out_right);

        buttonPrev.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewSwitcher.showPrevious();
            }
        });

        buttonNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewSwitcher.showNext();
            }
        });
    }
}

the file exists, it is in the same folder of slide_in_left and the latter if I can invoke it in android.R.anim.slide_in_left

here is the xml of slide_in_right (it's more .. when I give CTRL+CLICK I go to the xml, I mean it exists, but I get, cannot resolve symbol 'slide_in_right'

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/slide_in_right.xml
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="50%p" android:toXDelta="0"
            android:duration="@android:integer/config_mediumAnimTime"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
            android:duration="@android:integer/config_mediumAnimTime" />
</set>
    
asked by Andress Blend 15.12.2017 в 16:21
source

1 answer

1

If it is an animation that you made, you must ensure that the element is within res/anim/

This so you can load the resource correctly, but you have to do it this way:

lol = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);

If you have your resource and can not access it, you can perform a "Clean" of your project so that it can generate references again.

The problem is that you try to load animations from the SDK (you are using android.R.anim.) , and slide_in_right DOES NOT exist, it must be slide_out_right , in this case the name of the animations must be:

android.R.anim.slide_in_left 

and

android.R.anim.slide_out_right
    
answered by 15.12.2017 / 17:23
source