Android 如何从屏幕底部向上滑出一个view

Android 如何从屏幕底部向上滑出一个view

我的实现方式是使用Android 中的dialog实现的,直接看下面的代码步骤

1、定义dialog的布局




    
        
            
            
                
                
                
            

            
                
                
                    
                    
                    
                
            
            
            
                
                
                
                    
                    
                    
                
            

            
            
                

                

2、定义一个类,然后直接继承dialog

package com.dx.jingle.dialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.dx.jingle.R;
import com.dx.jingle.bean.DishesVoBean;
import com.dx.jingle.bean.ShoppingCartBean;
import com.dx.jingle.util.MainUtil;
import java.math.BigDecimal;

public class HomeShopDialog extends Dialog {
    private Context context;
    private DishesVoBean dishesVo;
    private OnItemClickListener onItemClickListener;
    private String strShop;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public HomeShopDialog(@NonNull Context context, DishesVoBean dishesVos) {
        super(context);
        this.context=context;
        this.dishesVo=dishesVo;
    }
    public HomeShopDialog(@NonNull Context context, int themeResId, DishesVoBean dishesVo) {
        super(context, themeResId);
        this.context=context;
        this.dishesVo=dishesVo;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置布局
        setContentView(R.layout.dialog_home_shop);
    }
    }
    public interface OnItemClickListener{
        void onBtnPlusClick(View view, ShoppingCartBean data, DishesVoBean datas);
    }
}

3、然后自定义一个点击事件

 //设置点击事件
        rvReserveHomeAdapter.setOnItemClickListener(new RvReserveHomeAdapter.OnItemClickListener() {
            @Override
            public void onBtnPlusClick(View view, DishesVoBean data, int position) {
                //1、初始化Dialog
                HomeShopDialog dialog=new HomeShopDialog(mActivityContext,R.style.DialogTheme,data);
                //获取Dialogwindow对象
		        Window window=dialog.getWindow();
		        //设置弹出位置
		        window.setGravity(Gravity.BOTTOM);
		        //设置动画
		        window.setWindowAnimations(R.style.dialog_menu_animStyle);
		        //设置对话框大小
		        window.getDecorView().setPadding(0,0,0,0);
		        WindowManager.LayoutParams layoutParams=window.getAttributes();
		        //设置宽度和高度
		        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
		        layoutParams.height=WindowManager.LayoutParams.WRAP_CONTENT;
		        //显示Dialog
		        dialog.show();

            }
        });

4、在styles.xml中设置dialog的样式


    
    
    

5、定义关闭与打开的动画效果

//结束


    


//打开


    
    

效果图:

你可能感兴趣的:(Android)