java - Android studio 弹出窗口?

标签 java android

我一直在尝试制作一个简单的弹出窗口,以便在用户点击 Sprite 时显示。我已经为弹出窗口做了布局,但它不显示。我错过了什么吗?

编辑:这是我的 Activity 类的其余部分:

public class UniverseActivity extends AppCompatActivity {

public static final String TAG = UniverseActivity.class.getSimpleName();

private UniverseThread thread;

private Galaxy player;
public Galaxy getPlayer() {
    return player;
}

//components:
private SeekBar speedBar;
private ProgressBar timeBar;
private UniverseView surfaceView;
private ImageView playerSprite;
private ImageView otherSprite;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_universe);

    speedBar = (SeekBar) findViewById(R.id.seekBar);
    timeBar = (ProgressBar) findViewById(R.id.progressBar);
    surfaceView = (UniverseView) findViewById(R.id.surfaceView);

    playerSprite = (ImageView) findViewById(R.id.playerGalaxy);
    player = new Galaxy("Milky Way", true, new Velocity(), playerSprite, 1);

    otherSprite = (ImageView) findViewById(R.id.otherGalaxy);

    playerSprite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupWindow infoWindow = new PopupWindow(findViewById(R.id.galaxy_info_popup));
            Log.d(TAG, "Player sprite clicked, stopping time and bringing up window...");
            Log.d(TAG, "Will this please work?");
            speedBar.setProgress(0);
            infoWindow.showAtLocation(surfaceView, Gravity.BOTTOM, 10, 10);
            infoWindow.update(50,50,300,500);
        }
    });
}

还有我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="300dp"
android:layout_height="500dp"
android:id="@+id/galaxy_info_popup"
android:background="#ffffff">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/nameText"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:id="@+id/infoPicture"
    android:layout_below="@+id/nameText"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="infoText"
    android:id="@+id/infoText"
    android:layout_below="@+id/infoPicture"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

最佳答案

最后一行应该像 -

     infoWindow.showAtLocation(surfaceView, Gravity.BOTTOM, 10, 10);
     infoWindow.update(50, 50, 300, 80);

希望它对你有用:)

关于java - Android studio 弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37820867/

相关文章:

java - 难以理解 Java 的构造函数、setter 和 getter

java - Spring:引用所有 Foo 类型的 bean

android - 如何在 WebView 文本选择菜单中保留标准的 'select all' 和 'copy' 菜单项?

java - 延迟行动

Java 关键字子串

android - 如何使用删除触发器删除同一个表中的行?

android检测充电器的安培数

android - 如何将预制数据库导入由 ormlite 管理的 sqlite

java - Jface:Listviewer 抛出 AssertionFailedException

java - LibGDX:无法在我的表中添加纹理