I'm currently trying to create a puzzle game where I have a grid and each cell should be able to show a visual (and only visual) indication on touch. Therefore, I intent to use the ViewGroupOverlay (with getOverlay()) with a custom view:
In each CellView
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.overlay, null);
gridView.getOverlay().add(myView);
}
if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
gridView.getOverlay().clear();
}
return super.onTouchEvent(event);
}
where 'gridView' is the parent (a FrameLayout containing a GridLayout that holds the multiple CellViews (which are RelativeLayout)) ;). But I think that doesn't really matters...
And currently for the overview.xml (Just dummy code)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddd090d">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test" />
</LinearLayout>
Sadly, the overlay view doesn't appear anywhere.
However, if I try it with a drawable and the following code in 'onTouchEvent', it works... But I would need the view and not the drawable to work...
Drawable myIcon = getResources().getDrawable(R.drawable.overlay);
myIcon.setBounds(0,0,100,100);
gridView.getOverlay().add(myIcon);
In general, the Overlay-technique added in API18 seems to be never used. Any experts here?