popuWindow
Xml佈局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/local_popup_bg"
android:orientation="horizontal" > <!-- 撥打電話 --> <LinearLayout android:id="@+id/ll_call" android:layout_width="40dip" android:layout_height="wrap_content" android:orientation="vertical" >
<ImageView android:layout_width="40dip" android:layout_height="wrap_content" android:src="@android:drawable/ic_menu_call" />
<TextView android:layout_width="40dip" android:layout_height="wrap_content" android:gravity="center" android:text="電話" /> </LinearLayout> <!-- 發送短信 --> <LinearLayout android:id="@+id/ll_sms" android:layout_width="40dip" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:orientation="vertical" >
<ImageView android:layout_width="40dip" android:layout_height="wrap_content" android:src="@android:drawable/ic_menu_send" /> <TextView android:layout_width="40dip" android:layout_height="wrap_content" android:gravity="center" android:text="短信" /> </LinearLayout>
</LinearLayout> |
Popu 代碼實現
View contentView=View.inflate(getApplicationContext(), R.layout.popu_dialog, null); //找到相應的控件進行操作1,撥打電話,2,發送短信 LinearLayout ll_call=(LinearLayout)contentView.findViewById(R.id.ll_call); LinearLayout ll_sms=(LinearLayout) contentView.findViewById(R.id.ll_sms);
//彈出popu對話框 pw=new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//背景透明 pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //寬,高的數組 int[] location=new int[2]; view.getLocationInWindow(location); pw.showAtLocation(view, Gravity.LEFT|Gravity.TOP, 30, location[1]); |