使用Androids默认选项卡应用程序,我应该将自己的xml代码放在activity_main的何处
这是Androids默认选项卡应用程序的activity_main.xml布局:使用Androids默认选项卡应用程序,我应该将自己的xml代码放在activity_main的何处,android,xml,android-fragments,android-viewpager,Android,Xml,Android Fragments,Android Viewpager,这是Androids默认选项卡应用程序的activity_main.xml布局: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-aut
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<!-- When I add my own view here and use match_parent, it fills ENTIRE screen, even over the Toolbar. The ViewPager right above does not do this. Why? -->
</android.support.design.widget.CoordinatorLayout>
我正试图将自己的按钮/文本视图等添加到我的活动\u main.xml
中,但我不知道在哪里添加它们。android.support.v4.view.ViewPager
使用match\u parent
尽管它不适合整个屏幕,但它在顶部的工具栏
区域之外扩展到整个屏幕。但是,每当我在android.support.v4.view.ViewPager
下面添加自己的视图时,让我们假设RelativeView
并将其设置为match\u parent
,它就会在工具栏上展开。这让我相信我应该把我的内容放在ViewPager
标签中,但这也不起作用
我应该将视图放在何处,以便它们不会与工具栏重叠?您可以将视图页面
包装在相对视图中,还可以添加视图子级
下面是可能对您有所帮助的代码片段-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="I am clickable" />
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/button"
android:background="@color/colorNeutral"
android:layout_above="@+id/button2" />
<Button
android:layout_marginBottom="56dp"
android:layout_alignParentBottom="true"
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="I am clickable too" />
</RelativeLayout>
在另一个文件中-片段的布局,然后您应该实现适配器,该适配器将为ViewPager提供片段…@Selvin我想将内容添加到我的主要活动中,而不是我的片段。例如,我希望在我的主要活动上有一个按钮,该按钮在所有选项卡上都保持不变。