【问题标题】:android custom floating windowandroid自定义浮动窗口
【发布时间】:2014-05-13 18:57:04
【问题描述】:

我必须自定义(我可以设置我的 layout.xml)浮动窗口,其中 我可以控制 Xco 和 Yco。

使用 Toast(在计时器中)我可以做到这一点,但我必须避免不必要的计时器。

我遇到了一些库说,SuperToolTip(我们无法控制 X 和 Y;而是我们放置在一些可绘制对象上)StandOut(在这里我们可以控制 Xco 和Yco,但它使用服务只是一件简单的事情)

请帮帮我。

已编辑

final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Translucent_NoTitleBar);

Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.x = 0;      
wlp.y = 200;
wlp.width = 800;
wlp.height= 400;
window.setAttributes(wlp);

dialog.setTitle(null);
View view = getLayoutInflater().inflate(R.layout.layout_audio_recording_hint, null);

dialog.setContentView(view);
dialog.setCancelable(false);

ImageButton imgBtnCloseDialog = (ImageButton)view.findViewById(R.id.imgBtnCloseDialog);
imgBtnCloseDialog.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        dialog.cancel();
    }


});


ImageButton imgBtnAudio = (ImageButton) findViewById(R.id.imgBtnAudio);
imgBtnAudio.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        dialog.show();
    }
});

【问题讨论】:

  • Dialog 怎么样?更改对话框位置:stackoverflow.com/questions/9467026/…
  • @Wenhui,感谢您的评论!对话框帮助我寻找我正在寻找的东西......
  • 只是一个建议,不要使用像素,而是使用密度像素。您的窗口位置和大小是像素,不能很好地跨不同的设备密度进行缩放。
  • @Wenhui,非常感谢您的宝贵建议。我始终牢记:)

标签: android window floating


【解决方案1】:

使用此代码 android.widget.PopupWindow 可用于显示任意视图。弹出窗口是一个浮动容器,出现在当前活动的顶部。

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" 
      android:background="@android:color/background_light">
      <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_margin="1dp"
        android:background="@android:color/darker_gray">
        >
      <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_margin="20dp">
      <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="It's a PopupWindow" />
      <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_launcher" />
      <Button
          android:id="@+id/dismiss"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Dismiss" />
     </LinearLayout>
     </LinearLayout>
     </LinearLayout>

【讨论】:

    猜你喜欢
    • 2014-11-08
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多