Gru*_*rux -2 android android-animation android-linearlayout
是否可以android:layoutAnimation使用Java以编程方式更改为其他动画资源?
是否可以
android:layoutAnimation使用Java以编程方式更改为其他动画资源?
是的:您可以使用LayoutAnimationController
布局动画控制器用于给一个layout's或一view组子项设置动画。每个孩子都使用相同的动画,但是对于每个孩子,动画在不同的时间开始。A layout animation controller用于ViewGroup计算每个孩子的动画开始必须偏移的延迟
这里正在使用示例代码
public class MainActivity extends AppCompatActivity {
LinearLayout rootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView=findViewById(R.id.rootView);
LayoutAnimationController anim = AnimationUtils.loadLayoutAnimation(this, R.anim.scale_down);
rootView.setLayoutAnimation(anim);
}
}
Run Code Online (Sandbox Code Playgroud)
Layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:id="@+id/buttonPanel"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
R.anim.scale_down
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/scale_up" />
Run Code Online (Sandbox Code Playgroud)
@ anim / scale_up
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="1000"
android:fromXScale="0"
android:fromYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
939 次 |
| 最近记录: |