Android Popup Menu fill parent

后端 未结 2 584

I try set my popup menu in way to fill hole item on grid. Currently it look like on attached first picture and the next one is effect which I would like to have.

<
2条回答
  •  误落风尘
    2021-01-21 13:40

    Demo App for your requirment by using PopupWindow. Preview

    You can add list in it or customize it according to your needs. MainActivity

    public class MainActivity extends Activity {
    
        boolean isClicked = true;
        PopupWindow popUpWindow;
        RelativeLayout relative;
        ImageView btnClickHere;
    
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            relative = (RelativeLayout) findViewById(R.id.relative);
            popUpWindow = new PopupWindow(this);
            popUpWindow.setContentView(getLayoutInflater().inflate(R.layout.popup_design, null));
            popUpWindow.getContentView().findViewById(R.id.textViewa).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this, "PopItemClicked", Toast.LENGTH_LONG).show();
                }
            });
    
            btnClickHere = (ImageView) findViewById(R.id.imageView);
            btnClickHere.setOnClickListener(new View.OnClickListener() {
    
                public void onClick(View v) {
                    if (isClicked) {
                        isClicked = false;
                        popUpWindow.setHeight(relative.getHeight());
                        popUpWindow.setWidth(relative.getWidth());
                        popUpWindow.showAsDropDown(relative, 0, -relative.getHeight());
                    } else {
                        isClicked = true;
                        popUpWindow.dismiss();
                    }
                }
            });
        }
    }
    

    activity_main.xml

    
    
    
        
    
            
        
    
    
    

    popup_design.xml

    
    
    
        
    
            
    
            
    
            
        
    
        
    
    
    

提交回复
热议问题