I am adding button programatically while clicking on button I need show PopupWindow in that button position when ever orientation is changing that button position also changes..
Asked
Active
Viewed 1.2k times
0
-
I think RelativeLayout could help to do so, make a popup window layout and hide it, display it when click the button. – Tom Sep 12 '12 at 10:18
-
Could you plz explain how it will works - Tom – Kiran Android Sep 12 '12 at 10:51
-
Check this answer [How to show PopupWindow at special location?](http://stackoverflow.com/a/7502433/3512164) – Ibrahim Disouki Aug 03 '15 at 22:54
1 Answers
1
I am trying to tell you what I thought to make it, may not be the best solution, just a reference. All sources here are pseudo-code.
Here is the parent layout, and set button and your popup window at same position:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_marginTop="80dp"
android:layout_marginLeft="80dp" >
</Button>
<com.yourdomain.android.PopupWindow
android:layout_marginTop="80dp"
android:layout_marginLeft="80dp"
android:visibility="GONE">
</com.yourdomain.android.PopupWindow>
</RelativeLayout>
Here is the layout of your popup window:
<LinearLayout
android:id="@+id/linearlayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" >
</LinearLayout>
Here you can create a class to bind to this layout, so its your custom component:
public class PopupWindow extends LinearLayout {
protected Context _context = null;
public PopupWindow (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
_context = context;
setupView(context);
}
public PopupWindow (Context context) {
super(context);
// TODO Auto-generated constructor stub
_context = context;
setupView(context);
}
public void setupView (Context context)
{
// here to initialize all children views in this layout
}
public void show ()
{
this.setVisibility (LinearLayout.Visible);
}
public void hide ()
{
this.setVisibility (LinearLayout.GONE);
}
}
I hope this helps.