如何设置基于android的按钮位置弹出窗口的位置? [英] How to set popup window position based on button position in android?

查看:214
本文介绍了如何设置基于android的按钮位置弹出窗口的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入编程键,同时点击按钮,我需要在该按钮的位置显示PopupWindow当过方向正在改变该按钮的位置也改变了。

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..

推荐答案

我想告诉你我的想法,使之,未必是最好的解决方案,只是一个参考。这里所有的来源是peso- code。

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 peso-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);
        }

}

希望它帮助。

这篇关于如何设置基于android的按钮位置弹出窗口的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆