Hi,
In my activity I'm experimenting to get an effect of a small button
floating over a list component in its bottom right corner. It seems
that there is no default view group component that would easily allow
for this. So I tried an approach of having a PopupWindow containing
the button rendered over the list. This is, roughly, the code I have
written:
private void initButton() {
View buttonView =
getLayoutInflater().inflate(R.layout.keyboard_button, null);
buttonPopup = new PopupWindow(buttonView);
buttonPopup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
final View container = findViewById(android.R.id.tabhost); //
root view
final View listContainer = findViewById(R.id.listContainer);
container.post(new Runnable() { // showing in onCreate() or
onStart() impossible
public void run() {
buttonPopup.showAtLocation(container, Gravity.CENTER,
0, 0);
// buttonPopup.update(listContainer, -1, -1);
// buttonPopup.showAsDropdown(listContainer);
}
});
}
(where initButton is called in onStart()) Unfortunately, the
'showAtLocation' method does not work (the popup does not show in a
visible location). Surprisingly, when I uncomment the call to update
right after showAtLocation, or replace showAtLocation with the
commented out call to showAsDropdown, it works, i.e. displays the
button, but obviously not in the desired location (below the list
container, as opposed to within it, as the list container becomes the
anchor). I experimented with different values of Gravity (that's why
it's set to CENTER in the above code, originally it was RIGHT |
BOTTOM) and different values of x and y, but without success. I don't
know if it is relevant, but there is also a tab control involved in
this activity (the tabhost is the root view group). Any insights? Why
'showAtLocation' would not work? Perhaps there is a better way of
achieving what I want to achieve (i.e. without PopupWindow)?
Cheers,
Dariusz
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en