12

我正在尝试为containerLinearLayout (20dp) 和btn按钮 (20dp) 设置动画(将它们向右移动),但在 LinearLayout (40dp) 的整个宽度之后它们会被剪裁main。我都试过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>

我的(简化的)代码:

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);
}

动画代码:

public void onClick(View v) {
btn.animate().xBy(100f).setDuration(2000);
container.animate().xBy(100f).setDuration(2000);
}
4

1 回答 1

0

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

在我的情况下,我必须使用动画视图windowManager.updateViewLayout(view,layoutParams)

于 2018-11-21T17:49:36.783 回答