我有一个自定义布局“MyLayout”,它扩展了
RelativeLayout
并膨胀了my_layout.xml
:
public class MyLayout extends RelativeLayout {
// the constructors are all calling init(context);
private void init(Context context) {
if (context != null) {
LayoutInflater.from(context).inflate(R.layout.my_layout, this);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
System.out.println("touched");
return super.onTouchEvent(event);
}
}
这是
my_layout.xml
,它有一个波纹动画:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative_layout"
android:clickable="false"
android:background="@drawable/ripple_background"
android:layout_width="match_parent"
android:layout_height="match_parent" />
现在这是当我改变
android:clickable
的值时会发生什么
|
|
---|---|
波纹动画不会出现 | 波纹动画按预期工作 |
将在触摸时被调用 |
永远不会被调用 |
我怎样才能让涟漪动画可见以及
onTouchEvent(MotionEvent)
在触摸时被调用?
android:focusable
等对波纹动画的可见性没有任何影响android:clickable="true"