2

2つのボタンを表示するアクティビティがあります。呼び出しボタンをクリックすると、画像に示すように別のアクティビティを表示したいと思います。

この種のレイアウトを表示する方法

助けてください。これを達成する方法

4

3 に答える 3

0

これを行う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);

次に、リスナーを実装する必要があります。

于 2012-10-10T09:59:14.527 に答える
0

これら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);
于 2012-10-10T10:02:14.560 に答える
0

これを関数に追加すると、ポップアップを使用できます。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
            }
        }
    }
于 2012-10-10T10:21:34.197 に答える