我正在尝试为container
LinearLayout (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);
}