开机广告页面2017流行样式 dialogTheme的popuwindow版本

不知道为啥,一些看过的东西不经常用,回头就忘记了,而且,忘记的干干净净

下面我们来复习一下popuwindow的知识,就能比较好的解决这个问题

参考资料

http://blog.csdn.net/harvic880925/article/details/49272285

开机广告页面2017流行样式 dialogTheme的popuwindow版本_第1张图片

PopDialogActivity
public class PopDialogActivity extends AppCompatActivity implements View.OnClickListener{
    private PopupWindow mPopWindow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pop_dialog);
        Button btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopupWindow();
            }
        });
    }

    private void showPopupWindow() {
        View contentView= LayoutInflater.from(PopDialogActivity.this).inflate(R.layout.pop_dialog,null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(contentView);
        ImageView iv1=(ImageView)contentView.findViewById(R.id.dia_iv);
        iv1.setOnClickListener(this);
        //显示popupwindow
        View rootview=LayoutInflater.from(PopDialogActivity.this).inflate(R.layout.activity_pop_dialog,null);
        mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
        mPopWindow.showAtLocation(rootview, Gravity.CENTER,0,0);
    }

    @Override
    public void onClick(View view) {
        int id =view.getId();
        switch (id){
            case R.id.dia_iv:
                mPopWindow.dismiss();
                break;
        }
    }
}

pop_dialog
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
    
    <ImageView
        android:id="@+id/mm"
        android:src="@mipmap/xj3"
        android:layout_width="200dp"
        android:layout_centerInParent="true"
        android:layout_height="270dp"/>

    <ImageView
        android:id="@+id/dia_iv"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignEnd="@+id/mm"
        android:layout_alignTop="@+id/mm"
        app:srcCompat="@mipmap/error"/>
    
RelativeLayout>

动画属性
context_menu_enter.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:duration="@android:integer/config_shortAnimTime"
        android:fromXDelta="0"
        android:fromYDelta="100%p"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toXDelta="0"
        android:toYDelta="0"/>

set>

context_menu_exit.xml


<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="@android:integer/config_shortAnimTime"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toXDelta="0"
        android:toYDelta="100%p" />

set>

styles

在项目中引入popupwindow

 mPopWindow.setAnimationStyle(R.style.contextMenuAnim);

勤学苦练,莫荒废终日

你可能感兴趣的:(android)