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

时间:2013-06-20 07:18:54

标签: android animation android-linearlayout

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

我的(简化)代码:

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

1 个答案:

答案 0 :(得分:0)

结果是您无法绘制使用windowManager.addView添加到屏幕的初始区域的边界。

就我的观点而言,我必须使用windowManager.updateViewLayout(view,layoutParams)