android - 如何在布局(不是 Activity )之间添加过渡

标签 android android-layout

我有一个应用程序,当用户单击表格行时,它会更改布局。 这是代码

 <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/cell_table"
                android:onClick="goAir" >

以及 onClick 的方法:

public void goAir(View view){
    setContentView(R.layout.va_air);
}

如何在布局变化之间添加过渡。像幻灯片一样的东西。

谢谢

最佳答案

有多种方法可以做到这一点。我更喜欢使用 Fragment。

/**
 * Adding given Fragment into content area without transition.
 * This is good for initializing view.
 * @param f
 */
private void addContentView(Fragment f){
    FragmentTransaction ft =getSupportFragmentManager().beginTransaction();
    ft.add(R.id.contentPane, f).commit();
}

/**
 * Replacing Fragment in content area with given Fragment
 * @param f Fragment to display
 * @param tag String of the content area
 * @param animIn Resource ID for new screen transition.
 * @param animOut Resource ID for old screen transition.
 */
private void replaceContentView(Fragment f, String tag, int animIn, int animOut){
    // -1 is passed when I want to use default animation.
    if(animIn == -1) animIn = R.anim.fragment_slide_left_enter;
    if(animOut == -1) animOut = R.anim.fragment_slide_left_exit;
    FragmentTransaction ft =getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(animIn, animOut); // Animate new view in and existing view out

    ft.replace(R.id.contentPane, f, tag); // id of the FrameLayout to put the Fragment in
    ft.commit();
}

关于android - 如何在布局(不是 Activity )之间添加过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11610918/

相关文章:

java - 聆听不同类(class)的 Mediaplayer 完成情况

android - 通过在android中放置一个中心以圆形方式放置imageviews

Android - 子类 ImageView - 错误膨胀类

java - 将内容 View 垂直更改为水平后,Android 按钮事件不起作用

android - 嗅探网络请求

java - Android 中的 recyclerview 中滚动时行项目宽度发生变化

android - 设备锁定时如何显示 Activity ?

Java:在读取进程的InputStream之前等待进程的子进程完成

java - Android 中两个重叠的 ImageView

java - 不允许在主线程之外调用 SetRefreshing(false)。解决方法?