如何在应用程序中显示android视图?

时间:2013-05-20 06:56:32

标签: android

我的Android应用登陆页面上有一个DrawingLayout。我想让它在整个应用程序中可见,以便我可以将其用作我的应用程序的导航控件。可能吗?如果是,我该如何实现?

提前多多感谢。

2 个答案:

答案 0 :(得分:1)

DrawingLayout放入您的每项活动中。

答案 1 :(得分:1)

创建一个返回线性布局的类,其中包含您在应用程序屏幕上所需的所有导航控件,并通过方法addView(lin_layout)将其添加到您的活动中;

看看这个

    public class yourClass{
        Context context;
        public LinearLayout createNavBar(int tooBarHeight,String mTitle, Context mContext)
        {

           LinearLayout topBar = new LinearLayout(mContext);
            topBar.setGravity(Gravity.TOP);
            topBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,tooBarHeight));   
            topBar.setBackgroundDrawable(d);

            TextView text = new TextView(mContext);
            text.setLayoutParams(new LayoutParams(width - 2*tooBarHeight,tooBarHeight));
            text.setGravity(Gravity.CENTER_VERTICAL);
            text.setText(mTitle);
            text.setTextColor(Color.WHITE);
            text.setPadding(15, 10, 0, 0);
            text.setTextSize(18);

            topBar.addView(text);

            Button home = new Button(mContext);
            home.setLayoutParams(new LayoutParams(tooBarHeight,LayoutParams.MATCH_PARENT));
            //home.setPadding(15, 15, 15, 15);
            home.setGravity(Gravity.RIGHT & Gravity.CENTER_VERTICAL);
            topBar.addView(home);

            home.setOnClickListener(new View.OnClickListener() {

            });

            Button order = new Button(mContext);
            order.setLayoutParams(new LayoutParams(tooBarHeight,LayoutParams.MATCH_PARENT));    
            order.setGravity(Gravity.RIGHT & Gravity.CENTER_VERTICAL);
            //order.setPadding(15, 15, 15, 15); 
            topBar.addView(order);

            order.setOnClickListener(new View.OnClickListener() {

            });

            return topBar;  
       }

} 您可以通过

将此导航栏添加到您的活动中
yourClass toolbar = new yourClass();
            LinearLayout topBar  = toolbar.createNavBar(72,"your title", mContext);         
            this.addView(topBar);