Popwindow及自下到上出现的方法

步骤:

  • 在res下新建anim文件夹
  • 在文件夹里新建pop_in.xml和pop_out.xml文件
  • 在style文件中配置动画
  • 在代码中引用

代码:
pop_in:



    

pop_out:



    

style:

    

activity中调用:



public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.btn);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopWindow();
            }
        });
    }

    private void showPopWindow() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.popwindow, null);

        PopupWindow popupWindow = new PopupWindow(inflate, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        // 设置popWindow弹出窗体可点击,这句话必须添加,并且是true
        popupWindow.setFocusable(true);

        popupWindow.setAnimationStyle(R.style.pop_anim);

        popupWindow.showAtLocation(findViewById(R.id.start), Gravity.BOTTOM,0,0);
    }
}

demo下载

你可能感兴趣的:(Popwindow及自下到上出现的方法)