【问题标题】:Recyclerview animation not working in activityRecyclerview 动画在活动中不起作用
【发布时间】:2020-07-25 18:08:43
【问题描述】:

我有一个包含 2 个片段的活动

StepsFragment 包含 Recyclerview 但 Recyclerview 的动画不起作用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="400dp"
    android:background="#B3D1DB"
    tools:context=".StepsFragment">

    <TextView
        android:id="@+id/inputEntred"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:visibility="invisible" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/RV"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:layoutAnimation="@anim/layou_animation_fall_down"
        android:paddingTop="10dp"
        android:paddingBottom="30dp" />
</RelativeLayout>

layout-animation-fall-down

    <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:animation="@anim/fall_down"
         android:animationOrder="normal"
           android:delay="15%">

跌倒

   <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="6000">
        <translate
            android:fromYDelta="-20%"
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:toYDelta="0"
            android:duration="1000" />
     <alpha
     android:fromAlpha="0"
     android:interpolator="@android:anim/accelerate_decelerate_interpolator"
     android:toAlpha="3"
         android:duration="1000"
     />
  <scale
      android:fromXScale="105%"
      android:fromYScale="105%"
      android:interpolator="@android:anim/accelerate_decelerate_interpolator"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toXScale="100%"
      android:toYScale="100%" android:duration="1000"
      />
</set>

活动布局

<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".Sorting_activity">


<RelativeLayout
    android:id="@+id/triLayout"
    android:layout_width="0dp"
    android:layout_height="300dp"
    app:layout_constraintBottom_toTopOf="@+id/stepsLayout"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

</RelativeLayout>

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/stepsLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/triLayout"></androidx.coordinatorlayout.widget.CoordinatorLayout>

步骤片段

 public class StepsFragment extends Fragment  {


private OnFragmentInteractionListener mListener;

private static TextView inputEntred  ;
private static RecyclerView RV ;
private Handler mhandler = new Handler();


public StepsFragment() {
    // Required empty public constructor
}

public void setTextView(String textentered){
    inputEntred.setText(textentered);
    String[] numberList = inputEntred.getText().toString().split(",");
    final Integer[] numbers = new Integer[numberList.length];
    SelectionSort m1 = new SelectionSort();
   ArrayList<String> mystepsList = m1.steps(numbers);// returns the steps numbers
    final StepListAdapter adapter = new StepListAdapter() ;
    RV.setAdapter(adapter);

    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    RV.setLayoutManager(llm);

        adapter.setList(mystepsList);

}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

     View view =inflater.inflate(R.layout.fragment_steps, container, false);
      inputEntred  =view.findViewById(R.id.inputEntred);
       RV =view.findViewById(R.id.RV);

    return view;
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof OnFragmentInteractionListener) {
        //   mListener = (OnFragmentInteractionListener) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}
public interface OnFragmentInteractionListener {
    // TODO: Update argument type and name
    void onFragmentInteraction(Uri uri);
}}

【问题讨论】:

  • 你愿意分享你的动画的 xml 吗?我认为错误可能在 xml 而不是您的代码中

标签: android-studio android-layout android-fragments android-recyclerview android-animation


【解决方案1】:

你能试试这个吗?我必须删除 XML 中不必要的持续时间。谢谢

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="250">

    <translate
        android:fromYDelta="-20%"
        android:toYDelta="0"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

    <scale
        android:fromXScale="105%"
        android:fromYScale="105%"
        android:toXScale="100%"
        android:toYScale="100%"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

</set>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多