Reputation: 286
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..
Upvotes: 0
Views: 11684
Reputation: 4652
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.
Upvotes: 1