2016-06-14 5 views
0

私は、ユーザーがスプライトをタップしたときに表示される単純なポップアップウィンドウを作ろうとしてきました。私はポップアップのためのレイアウトを作った、それは表示されません。何か不足していますか?Androidスタジオのポップアップウィンドウ?

編集:ここに私の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); 
     } 
    }); 
} 

そして、私のレイアウト:

実際のポップアップウィンドウのサイズを設定しない PopupWindow(View view)コンストラクタを使用して
<?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" /> 

答えて

0

私はPopUpWindow作業を取得することができませんでしたが、私はAndroidのとはるかに簡単に同じ効果を得ましたDialogクラス。

これは私がなってしまったものです:onClickListenerで

infoPopUp = new Dialog(this); 
infoPopUp.setContentView(R.layout.info_popup); 

Log.d(TAG, "Player sprite clicked, stopping time and bringing up window..."); 
speedBar.setProgress(0); 
infoPopUp.setTitle(player.getName()); 
((ImageView)infoPopUp.findViewById(R.id.infoPicture)).setImageDrawable(player.getSprite().getDrawable()); 
infoPopUp.findViewById(R.id.option1).setVisibility(View.INVISIBLE); 
infoPopUp.findViewById(R.id.option2).setVisibility(View.INVISIBLE); 
infoPopUp.findViewById(R.id.continueButton).setVisibility(View.VISIBLE); 
((TextView)infoPopUp.findViewById(R.id.infoText)).setText(player.toString()); 
infoPopUp.show(); 
0

。これはデフォルトで0の高さと0の幅になります。ポップアップを作成した後にsetWidth()setHeight()に電話をかけたり、他のコンストラクタを使用したりする必要があります。 Hereは、PopupWindowsに関するAndroidのドキュメントです。おそらくPopupWindow(View view, int width, int height)を使用します。別の問題は、あなたが渡しているビューが状況によっては正しく膨張されなかったり、無効である可能性があります。別の解決策は、update()に電話し、あなたが望むサイズを指定することです。

最後の行は次のようにする必要があります
1

-

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

それはあなたのために働くことを願っています:)

+0

私はちょうどsurfaceviewに)で、同様にsurfaceView.findFocus(変更されたことを置きます。しかし、まだ、何も表示されていません。 –

+0

あなたのレイアウトとアクティビティクラスを共有すれば、問題のトラブルシューティングが容易になります。 – Neo

+0

私はすべてを編集しました –

関連する問題