码迷,mamicode.com
首页 > 其他好文 > 详细

多个提示点击出现

时间:2014-12-02 09:04:23      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:android   style   http   io   ar   os   sp   on   log   

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="@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="@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="@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="@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>


多个提示点击出现

标签:android   style   http   io   ar   os   sp   on   log   

原文地址:http://blog.csdn.net/limingnanhai/article/details/41658297

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!