简体   繁体   English

在多个活动中重用布局的最简单方法

[英]Easiest way to re-use layout in multiple activities

I'm trying to use a NavBar ( http://imgur.com/a/fygH3 ) at the bottom of each page/activity. 我正在尝试在每个页面/活动的底部使用NavBar( http://imgur.com/a/fygH3 )。 when an image is clicked, it opens a new page. 单击图像后,将打开一个新页面。 Such as a page containing a countdown timer. 例如包含倒数计时器的页面。

Would the best way to do this be load the navbar layout onto the bottom of a page containing a countdown timer.Or is it possible to just use one navbar layout page that has a mainActivity layout, then load a countdownPage into the main activity layout, upon a button press? 最好的方法是将导航栏布局加载到包含倒数计时器的页面底部。或者可以只使用一个具有mainActivity布局的导航栏布局页面,然后将countdownPage加载到主活动布局中,按下按钮?

This would be done for 5 different activities/pages. 这将针对5个不同的活动/页面完成。

You could create a bottom layout, then add it on your layout's activities. 您可以创建底部布局,然后将其添加到布局的活动中。

Generic Layout my_bottom_layout.xml 通用布局my_bottom_layout.xml

<RelativeLayout android:id="@+id/bottom_layout">
  <RecyclerView/>
</RelativeLayout>

Layout's Activities 布局活动

<RelativeLayout
android:id="@+id/layout_1">

...

<include layout="@layout/my_bottom_layout" />
</RelativeLayout>


<RelativeLayout
android:id="@+id/layout_2">

...

<include layout="@layout/my_bottom_layout" />
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM