FrameLayout的子类ViewAnimator
来源:互联网 发布:mac 无法下载flash 编辑:程序博客网 时间:2024/05/16 11:01
ViewAnimator
public class ViewAnimator extends FrameLayout
FrameLayout容器的基类,用于在其视图之间切换时执行动画。
我们都了解FrameLayout布局的特性,在FrameLayout中添加的View都默认位于左上角,按照添加的顺序,最后添加的View位置最上层。
ViewAnimator的使用就是调整ViewAnimator包裹的子View的显示层次,可以通过setDisplayedChild(int whichChild)方法,设置哪一个子View将被显示。
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/sample_main_layout"> <ViewAnimator android:id="@+id/sample_output" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1"> <ScrollView style="@style/Widget.SampleMessageTile" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView style="@style/Widget.SampleMessage" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="@dimen/horizontal_page_margin" android:paddingRight="@dimen/horizontal_page_margin" android:paddingTop="@dimen/vertical_page_margin" android:paddingBottom="@dimen/vertical_page_margin" android:text="@string/intro_message" /> </ScrollView> <fragment android:name="com.example.android.common.logger.LogFragment" android:id="@+id/log_fragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </ViewAnimator> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> <FrameLayout android:id="@+id/sample_content_fragment" android:layout_weight="2" android:layout_width="match_parent" android:layout_height="0px" /></LinearLayout>
menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:ignore="AppCompatResource"> <item android:id="@+id/menu_toggle_log" android:showAsAction="always" android:title="Show Log" /></menu>
Activity
public class MainActivity extends SampleActivityBase { // Whether the Log Fragment is currently shown private boolean mLogShown; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); SwipeRefreshListFragmentFragment fragment = new SwipeRefreshListFragmentFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem logToggle = menu.findItem(R.id.menu_toggle_log); //R.id.sample_output对应的组件是否是ViewAnimator或其子类的一个实例,若是,menu_toggle_log,显示 logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator); //logFragment显示的状态不同显示不同字符 logToggle.setTitle(mLogShown ? Hide Log: Show Log); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { //用于修改menu_toggle_log显示的字符串及ViewAnimator显示的view switch(item.getItemId()) { case R.id.menu_toggle_log: mLogShown = !mLogShown; ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output); if (mLogShown) { //显示LogFragment output.setDisplayedChild(1); } else { //显示user guide output.setDisplayedChild(0); } //使Activity的选项菜单无效。 //这将导致菜单的相关演示文稿通过在下一次请求菜单时 //通过调用onCreateOptionsMenu和onPrepareOptionsMenu进行完全更新。 supportInvalidateOptionsMenu(); return true; } return super.onOptionsItemSelected(item); }}
阅读全文
1 0
- FrameLayout的子类ViewAnimator
- ViewAnimator及其子类ViewSwitcher,ViewFipper的使用
- ViewAnimator类及其子类的介绍
- ViewAnimator及其子类
- Android ViewAnimator及其子类
- VIewAnimator及其子类
- UI组件:ViewAnimator及其子类
- ViewAnimator 之(三) ViewAnimator及其子类分析
- Android的ViewAnimator及其子类ViewSwitcher-android学习之旅(三十三)
- Android学习笔记(25):带动画效果的View切换ViewAnimator及其子类
- 安卓UI控件-ViewAnimator及其子类
- android基础-ProgressBar及其子类和ViewAnimator及其子类
- android视图切换动画:ViewAnimator类及其子类
- 【android_温故知新】第 6 组 UI 组件:ViewAnimator 及其子类
- EasyDemo*ViewAnimator及其子类体系结构图(on Github)
- ViewAnimator控制视图的隐藏与显示
- ObjectAnimator 属性动画 缩放, ViewAnimator的用法
- 【FrameLayout】使用FrameLayout应该注意的地方
- PHP中上传图片增加水印小案例
- RabbitMQ与Redis队列对比
- python面向对象编程
- Node.js 初次使用心得
- Servlet接口五种方法介绍
- FrameLayout的子类ViewAnimator
- 以 Broadcom Corporation BCM4311, BCM4312为基础的无线网络卡
- 虚函数
- CAS算法和重入锁的实现的简单理解(1)
- [PAT乙级]1052. 卖个萌 (20)
- docker技术浅谈
- Java:关于方法的返回值的用法及代码说明
- [编程之美-16]层序打印二元树,每层打印一行
- 安装PHPMyAdmin