2013年2月15日金曜日

PopUp Window


popup.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@color/LightSkyBlue">

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
<ImageView
    android:id="@+id/popImg"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:src="@drawable/dark"
    android:layout_margin="10dp"
    />
<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
<TextView
   android:id="@+id/popTitle"
   android:layout_width="500dp"
   android:layout_height="70dp"
   android:text="title"
   android:textSize="30dp"
   android:layout_margin="10dp"
   />
<TextView
   android:id="@+id/popDetail2"
   android:layout_width="400dp"
   android:layout_height="70dp"
   android:text="title"
   android:textSize="16dp"
   android:textColor="@color/red"
   android:layout_margin="10dp"
   />
<TextView
   android:id="@+id/popDetail1"
   android:layout_width="400dp"
   android:layout_height="140dp"
   android:text="title"
   android:textSize="16dp"
   android:layout_margin="10dp"
   />    
</LinearLayout>
</LinearLayout>
<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btnPlay"
    android:layout_width="200dp"
    android:layout_height="50dp"
    android:layout_marginLeft="150dp"
    android:background="@drawable/btndmy"
    android:textColor="@android:color/white"
    android:textSize="30dp"
    android:text="PLAY" />

<Button
    android:id="@+id/btnCancel"
    android:layout_width="200dp"
    android:layout_height="50dp"
    android:layout_marginLeft="50dp"
    android:background="@drawable/btndmy"
    android:textColor="@android:color/white"
    android:textSize="30dp"
    android:text="Cancel" />
</LinearLayout>
</LinearLayout>

java


LayoutInflater layoutInf 
    = (LayoutInflater)getBaseContext()
     .getSystemService(LAYOUT_INFLATER_SERVICE);  
    View popupView = layoutInf.inflate(R.layout.popup, null);  
PopupWindow popupwindow = new PopupWindow(popupView);
popupwindow.setHeight(450);
popupwindow.setWidth(750);
popupwindow.showAtLocation(view, Gravity.CENTER, 0,0);
TextView title =(TextView)popupView.findViewById(R.id.popTitle);
TextView detail1 =(TextView)popupView.findViewById(R.id.popDetail1);
TextView detail2 =(TextView)popupView.findViewById(R.id.popDetail2);
title.setText(Title[id]);
detail1.setText(Detail1[id]);
detail2.setText(Detail2[id]);
ImageView img = (ImageView)popupView.findViewById(R.id.popImg);
int drawableID = getResources().
getIdentifier(ImageFile[id], "drawable", getPackageName());
img.setImageResource(drawableID);

//Cancel Button
Button btnCancel = (Button)popupView.findViewById(R.id.btnCancel);
    btnCancel.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
popupwindow.dismiss();
}});

//Play Button
Button btnPlay = (Button)popupView.findViewById(R.id.btnPlay);
btnPlay.setId(id);
    btnPlay.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
popupwindow.dismiss();
play(v.getId());
}});



0 件のコメント:

コメントを投稿