LinearLayout animate()剪辑视图,clipChildren不起作用

Pha*_*at7 12 animation android android-linearlayout

我正在尝试为containerLinearLayout(20dp)和btn按钮(20dp)设置动画(向右移动它们),但它们会在mainLinearLayout(40dp)的整个宽度之后被剪切.我试过clipChildren="false"这两个,但它不起作用.我不能使用match_parent尺寸布局,因为它是一个叠加应用程序,将阻止后面的触摸.

有任何想法吗?

我的布局:

<LinearLayout
    android:id="@+id/main"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clipChildren="false"
    android:clipToPadding="false" >

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="20dp"
        android:layout_height="80dp"
        android:clipChildren="false"
        android:clipToPadding="false" >        
    </LinearLayout>

    <ImageButton
        android:id="@+id/btn"
        android:layout_width="20dp"
        android:layout_height="80dp"
        android:padding="0dp"
        android:background="@drawable/btn" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的(简化)代码:

super.onCreate();       
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
params = new WindowManager.LayoutParams(
    LayoutParams.WRAP_CONTENT, //can't have MATCH_PARENT
    LayoutParams.WRAP_CONTENT, //can't have MATCH_PARENT
    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | 
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
    PixelFormat.TRANSLUCENT);

LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
main = (LinearLayout) inflater.inflate(R.layout.main,null);

btn = (ImageButton)main.findViewById(R.id.btn);
container = (LinearLayout)main.findViewById(R.id.container);
btn.setOnClickListener(onClickListener);        
windowManager.addView(main, params);
}
Run Code Online (Sandbox Code Playgroud)

动画代码:

public void onClick(View v) {
btn.animate().xBy(100f).setDuration(2000);
container.animate().xBy(100f).setDuration(2000);
}
Run Code Online (Sandbox Code Playgroud)

Pha*_*at7 0

事实证明,您无法在使用添加到屏幕的初始区域的边界之外进行绘制windowManager.addView

就我而言,要使视图动画化,我必须使用windowManager.updateViewLayout(view,layoutParams).