2つのボタンを表示するアクティビティがあります。呼び出しボタンをクリックすると、画像に示すように別のアクティビティを表示したいと思います。
助けてください。これを達成する方法
これを行う1つの方法は、ビューグループを使用して各アクティビティに追加するカスタムレイアウトを作成することです。
private View view;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewGroup parent = (ViewGroup) findViewById(R.id.linearLayout1);
view = LayoutInflater.from(getBaseContext()).inflate(R.layout.custom_layout,
null);
parent.addView(view);
次に、リスナーを実装する必要があります。
これら2つのボタンのxmlファイルを作成し、LayoutInflatorを使用してその新しいxmlを古いものに追加する必要があります。たとえば、1)新しいxml
LayoutInflator buttons = LayoutInflater.from(getBaseContext()).inflate(R.layout.buttons,
currentxml, false);
2)id->を介して参照される古いxml親
RelativeLayout relativeLayout = (RelatveLayout) findViewById(R.id.oldxml);
3)ここで追加します。
relativeLayout.addView(buttons);
これを関数に追加すると、ポップアップを使用できます。Popuserは、xml
膨らませたいファイルです。
public void popupshow(){
try{
LayoutInflater inflater=(LayoutInflater)SRSDMain.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Display display=getWindowManager().getDefaultDisplay();
int width=display.getWidth()/2;
int height=display.getHeight()/2;
View pop=inflater.inflate(R.layout.popupuser,null,false);
pop.measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.UNSPECIFIED);
height=pop.getMeasuredHeight();
width=pop.getMeasuredWidth()+50;
pu=new PopupWindow(pop,width,height,true);
pu.showAtLocation(findViewById(R.id.ll3),Gravity.CENTER,1,1);
Button btn=(Button)pu.getContentView().findViewById(R.id.button);
btn.getBackground().setColorFilter(new LightingColorFilter(0xFF505450,0xFF101010));
btn.setTextColor(Color.WHITE);
btn.setTypeface(null,Typeface.BOLD);
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//anything you want to do
pu.dismiss();
}
});
}
catch(Exception ex){
//Catch The Exception
}
}
}