在其他视图顶部显示的圆形显示错误“无法在独立视图上启动此动画制作工具”

时间:2015-09-18 02:11:27

标签: android animation circularreveal

我已经进行了几天的研究,但没有得到解决。 this Question中的问题与我的相似,但我也无法解决我的问题。

我试图像whatsapp那样获得圆形显示效果,其中显示的视图将在其他视图的顶部膨胀。在我的情况下,当我在已经存在于当前java类的layout.xml中的布局上应用动画时,它的工作正常,但问题是在我的情况下,LInearLayout的显示布局将推送其他内容(在其下面)倒下并为它腾出空间。

我在这种情况下的布局如下,

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<io.codetail.widget.RevealFrameLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
       <LinearLayout
           android:id="@+id/reveal_items"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"  >
           <LinearLayout
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:layout_weight="1"
               android:gravity="center"
               android:orientation="vertical">
               <ImageButton
                   android:layout_width="70dp"
                   android:layout_height="70dp"
                   android:background="@drawable/icon_camera" />
               <TextView
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginTop="16dp"
                   android:text="Gallery" />
           </LinearLayout>
           <!-- Other 2 icons here-->

       </LinearLayout>
   </io.codetail.widget.RevealFrameLayout>

   <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Enter Name" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="OK" />

的LinearLayout /&GT;

我的显示布局会将EditText和按钮向下移动以便为它创建,但我想透露它们的顶部..

然后我尝试将显示的视图代码放在另一个reveal-layout.xml文件中,并将该布局扩展到在javacode中创建的View(在我的情况下为LinearLayout)。然后尝试在这个LinearLayout上应用显示效果,但它给了我“无法在分离视图上启动此动画师”异常。

我的revealing-layout.xml看起来像

<io.codetail.widget.RevealFrameLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
       <LinearLayout
           android:id="@+id/reveal_items"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"  >
           <LinearLayout
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:layout_weight="1"
               android:gravity="center"
               android:orientation="vertical">
               <ImageButton
                   android:layout_width="70dp"
                   android:layout_height="70dp"
                   android:background="@drawable/icon_camera" />
               <TextView
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginTop="16dp"
                   android:text="Gallery" />
           </LinearLayout>
           <!-- Other 2 icons here-->

       </LinearLayout>
   </io.codetail.widget.RevealFrameLayout>

在按钮中单击我调用函数 revealView(); 看起来如下,

public void revealView()
{
    int cx = (mRevealView.getLeft() + mRevealView.getRight());
    int cy = mRevealView.getTop();
    int radius = Math.max(mRevealView.getWidth(), mRevealView.getHeight());

    // and all animations here, the animator is working fine so i did not put the code here
} 

如果我在我的MainActivity onCreate() 中初始化mRevealView,则 mRevealView =(LinearLayout)findviewbyid(R.id.reveal_items)< / em> 并对其进行充气和分配视图,然后动画师将在此视图上正常工作。但是当我尝试创建新的布局时, mRevealView = new LinearLayout(this) 并设置其参数等一切然后当我在其上应用动画制作时会出现此错误。 无法在分离视图上启动此动画。

我在这里做错了可以有人建议我。

2 个答案:

答案 0 :(得分:1)

尝试将您的曝光代码放在ViewTreeObserver预期的布局布局中,如下所示:

boolean reveal = false;
button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            reveal = true;
        }
    });

LinearLayout layout = (LinearLayout) findViewById(R.id.reveal_items);
layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {                        
            if(reveal) {
                reveal = false;
                // start reveal animation here
                // ...
            }
            // for SDK >= 16
           ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
 });

答案 1 :(得分:1)

为了达到类似whatsapp的效果,使用像你所提到的whatsapp库这样的循环效果我首先将我的父视图设置为FrameLayout。这个父Framelayout包括两个孩子,第一个是LinearLayout,第二个是FrameLayout(这里是想要在LinearLayout中写的视图上显示的代码)。如上所述,在第一个LinearLayout中显示您想要显示在屏幕上的所有代码,在第二个FrameLayout中显示显示效果代码。它只是使用FrameLayout属性。你已准备好出发。 您可以使用库中描述中提供的相同Java代码。