如何为所有活动使用相同的SlidingUpPanel

时间:2017-01-24 09:52:11

标签: android android-layout android-activity drawerlayout slidingdrawer

var MyClassInstances = [];
var MyClass = function() { //constructor
   MyClassInstances.push(this); //push the new instance
}

以上是我的SlidingUpPanel的XML代码,它在我的主要活动中使用。它有两个部分,主要内容(正常屏幕)和滑动内容(将来自屏幕底部)。现在问题这个面板只会显示在主要活动中。我想显示所有活动的面板。指导我如何去做。

请帮助 感谢.. !!

2 个答案:

答案 0 :(得分:0)

如果您想在所有活动中使用相同内容的相同滑动菜单,那么只需创建一个活动并编写滑动菜单的逻辑,然后将其名称命名为BaseActivity,然后将此BaseActivity扩展到所有其他活动中项目的活动而不是AppCompatActivity,因此您可以在所有活动中使用它。

另一种方法是包含SlidingMenu的Fragment,如@Veeresh在评论中所建议的那样,这也是一个很好的选择

回答您的评论会在您的MainActivity中创建一个变量,如此

 public  SlidingUpPanelLayout ss; // this is important step , did you followed this in your mainactivity

它的类变量然后在onCreate方法

ss=(SlidingUpPanelLayout) findViewById(R.id.sliding_layout);

然后在其他活动中,您可以通过ss

直接获取

答案 1 :(得分:0)

在单独的布局中创建滑动内容,并在任何活动中对其进行充气

 LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);


        View inflatedLayout = inflater.inflate(R.layout.layout1, null, false);
        inflatedLayout.setLayoutParams(lp);