【问题标题】:Add Footer for whole Android Application为整个 Android 应用程序添加页脚
【发布时间】:2013-10-16 09:39:42
【问题描述】:

在我的应用程序中,每个activity 都有一个页脚。基本上我在页脚中有一个ImageView,它从Web service 获取图像(添加图像)并在一段时间间隔后更改图像(如滑动添加)。我正在做的是在每个活动中添加页脚并在每个活动中调用 Web 服务以将图像加载到 ImageView (这对我的应用程序来说将是一个非常繁重的处理,因为我的应用程序中有很多 Java classes(Activities)),所以我的问题是…… 在android中有什么方法可以为整个应用程序添加页脚吗?就像我在底部的first activity 添加页脚,现在如果我移动到second activity, third activity 等等....页脚将仍然存在,我已在first activity 中添加。 (与 iPhone Navigation controller 相同)

提前致谢

【问题讨论】:

    标签: android footer


    【解决方案1】:

    以编程方式创建您的视图,然后将其存储在可在整个应用程序中访问的单例对象中,这将避免每次都必须创建一个新视图。

    单例类示例:

    public class MySingleFooter{
    MySingleFooter mySingleFooter;
    View myFooter;
    
    private MySingleFooter(){}
    
    public static MySingleFooter getInstance()
    {
    if (mySingleFooter == null)
        {
        mySingleFooter = new MySingleFooter();
        }
    
    return mySingleFooter;
    }
    
    void setFooter(View myFooter)
    {
        this.myFooter = myFooter;
    }
    
    View getFooter()
    {
        return myFooter;
    }}
    

    您可以像这样设置所有活动的页脚:

    MySingleFooter footerStore = MySingleFooter.getInstance(); footerStore.setFooter(thefooter);

    您可以像这样从所有活动中检索页脚:

    MySingleFooter footerStore = MySingleFooter.getInstance(); View myview = footerStore.getFooter(thefooter);

    然后以编程方式将其添加到当前活动中。

    【讨论】:

      【解决方案2】:

      制作一个您想在应用程序的所有屏幕上显示的页脚 xml 文件,然后按照以下步骤操作:

      创建一个 Footer.java 活动

      public class Footer extends Activity {
              public void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                   setContentView(R.layout.footer);
              }
       }
      

      然后在另一个类上扩展该类以供如下使用:

      public class Test extends Footer 
      {
              @Override
              public void onCreate(Bundle savedInstanceState)
              {
                  super.onCreate(savedInstanceState);
                  ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
                  ViewGroup.inflate(Home.this, R.layout.test, vg);
              }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-07-21
        • 2018-01-18
        • 2010-12-24
        • 2011-11-05
        • 1970-01-01
        • 1970-01-01
        • 2011-10-19
        • 2019-11-01
        • 1970-01-01
        相关资源
        最近更新 更多