首页 > 代码库 > 多个提示点击出现

多个提示点击出现

xml 

最外层加android:background="#aa000000"

设置popupwindow,handler,如果隔多少秒消失还需要handler发空消息





设置popupwindow:

private void showPopup(View view) {

popupWindow = new PopupWindow(view,
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
}

runnable:

final Runnable showPopWindowRunnable = new Runnable() {


@Override
public void run() {
LinearLayout main_line=(LinearLayout)findViewById(R.id.main_line);
if (main_line != null && main_line.getWidth() > 0
&& main_line.getHeight() > 0) {
popupWindow.showAtLocation(main_line, Gravity.CENTER
| Gravity.CENTER, 0, 0);// 在屏幕的中间位置显示
DebugLog.i("Log",
"==========height=" + popupWindow.getHeight());
popupWindow.update();
handler.removeCallbacks(this);
} else {
handler.postDelayed(this, 5);
}
}
};

触发事件:

/*
* 显示popupwindow并且更换不同内容,添加事件
*/
private void makePopup() {
// TODO Auto-generated method stub
final LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
final View view=mLayoutInflater.inflate(R.layout.net_control_list_help_two,
null, true);
ViewGroup mView = (ViewGroup) mLayoutInflater.inflate(R.layout.net_control_list_help_one,
null, true);
ImageView imgLeft=(ImageView)mView.findViewById(R.id.img_left);
ImageView imgRight=(ImageView)mView.findViewById(R.id.img_right);
final View viewthree=mLayoutInflater.inflate(R.layout.net_control_list_help_three,
null, true);
ImageView imgLeftthree=(ImageView)viewthree.findViewById(R.id.img_left);
ImageView imgRightthree=(ImageView)viewthree.findViewById(R.id.img_right);
showPopup(mView);
final View viewfour=mLayoutInflater.inflate(R.layout.net_control_list_help_four,
null, true);
final Runnable showPopWindowRunnable = new Runnable() {


@Override
public void run() {
LinearLayout main_line=(LinearLayout)findViewById(R.id.main_line);
if (main_line != null && main_line.getWidth() > 0
&& main_line.getHeight() > 0) {
popupWindow.showAtLocation(main_line, Gravity.CENTER
| Gravity.CENTER, 0, 0);// 在屏幕的中间位置显示
DebugLog.i("Log",
"==========height=" + popupWindow.getHeight());
popupWindow.update();
handler.removeCallbacks(this);
} else {
handler.postDelayed(this, 5);
}
}
};
imgRight.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
showPopup(viewthree);
handler.post(showPopWindowRunnable);
}
});
imgLeft.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
showPopup(view);
handler.post(showPopWindowRunnable);
handler.sendEmptyMessageDelayed(12345, 3000);
}
});
imgRightthree.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
showPopup(viewfour);
handler.post(showPopWindowRunnable);
handler.sendEmptyMessageDelayed(12345, 3000);
}
});
imgLeftthree.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
showPopup(view);
handler.post(showPopWindowRunnable);
handler.sendEmptyMessageDelayed(12345, 3000);
}
});
handler.post(showPopWindowRunnable);

}


handler中:

handler=new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
if(msg.what==1234){
getList();

}
if(msg.what==12345){
popupWindow.dismiss();
}
}
};



所有的xml:

net_control_list_help_one:

<?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:background="#aa000000"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="50dp"
            android:orientation="horizontal" >
            <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="75dp"
            android:layout_marginLeft="50dp"
            android:src=http://www.mamicode.com/"@drawable/net_control_list_help_addcontrol_arrow_study" />
        </LinearLayout>




        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="50dp"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/img_left"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:layout_marginLeft="30dp"
                android:background="@drawable/net_control_list_button_jump" />


            <ImageView
                android:id="@+id/img_right"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:layout_marginLeft="15dp"
                android:background="@drawable/net_control_list_button_next" />
        </LinearLayout>
    </RelativeLayout>


</LinearLayout>


net_control_list_help_three:

<?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:background="#aa000000"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="50dp"
            android:orientation="horizontal" >
            <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="75dp"
            android:layout_marginRight="28dp"
            android:src=http://www.mamicode.com/"@drawable/net_control_list_help_addcontrol_arrow_longclick" />
        </LinearLayout>




        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="50dp"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/img_left"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:layout_marginLeft="30dp"
                android:background="@drawable/net_control_list_button_jump" />


            <ImageView
                android:id="@+id/img_right"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:layout_marginLeft="15dp"
                android:background="@drawable/net_control_list_button_next" />
        </LinearLayout>
    </RelativeLayout>


</LinearLayout>


net_control_list_help_two:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aa000000">




        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="50dp"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/img"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:src=http://www.mamicode.com/"@drawable/net_control_list_button_pup_up_text"
                android:textSize="20sp"/>


        </LinearLayout>


</RelativeLayout>



net_control_list_help_four:

<?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:background="#aa000000"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="50dp"
            android:orientation="horizontal" >
            <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="183dp"
            android:layout_marginRight="10dp"
            android:src=http://www.mamicode.com/"@drawable/net_control_list_help_addcontrol_arrow_more" />
        </LinearLayout>




        <!-- <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="50dp"
            android:orientation="horizontal" >


            <ImageView
                android:id="@+id/img_left"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:layout_marginLeft="30dp"
                android:background="@drawable/net_control_list_button_jump" />


            <ImageView
                android:id="@+id/img_right"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:layout_marginLeft="15dp"
                android:background="@drawable/net_control_list_button_next" />
        </LinearLayout> -->
    </RelativeLayout>


</LinearLayout>


多个提示点击出现