0
我試圖與佈局從屏幕底部向上浮動創建的應用程序使用TabLayout,但我對屏幕底部的標籤,所以我想隱藏他們的佈局動畫飄了起來。我的問題是如何訪問在其他xml文件中的選項卡布局,而不是在動畫中已經使用的RelativeLayout。我還在其他文件中定義了TabLayout,而不是用於動畫。
我的XML文件看起來像
FragmentsActivity:如何片段
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.young.howittastes.FragmentsActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="5dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:id="@+id/viewPager"
android:background="#d8d8d8"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tab_layout"
app:tabMode="fixed"
android:background="?attr/colorPrimary"
android:elevation="6dp"
app:tabTextColor="#d3d3d3"
app:tabSelectedTextColor="#ffffff"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
和家庭片段:
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerlayout">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="animation"
android:id="@+id/animationButton"
android:layout_centerHorizontal="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#d3d3d3"
android:id="@+id/commentLayout"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:elevation="6dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WRITE"
android:textSize="14sp"
android:textColor="#000"
android:textStyle="bold"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="READ"
android:textSize="14sp"
android:textColor="#030303"
android:textStyle="normal"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</RelativeLayout>
片段具有類onCreateView和ContentAdapter。 TabLayout定義這樣的,但它在其他的文件比片段定義中,我使用的動畫:
TabLayout tabs = (TabLayout) findViewById(R.id.tab_layout);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
adapter.addFragment(new HomeContent(), "Home");
adapter.addFragment(new FavoritesContent(), "Favorite");
adapter.addFragment(new FavoritesContent(), "Search");
adapter.addFragment(new FavoritesContent(), "Write");
viewPager.setAdapter(adapter);
tabs.setupWithViewPager(viewPager);
如果我會爲唯一的TabBar其他XML文件並將其包含在它不工作這兩個XML文件,如果我將包括它只能在正在處理的片段,使第二視圖中的Java文件來定義它,它不工作的xml文件沒有第二個視圖它也不工作。 – LisSkis
你能更具體地瞭解什麼是不工作? 「第二視圖」是什麼意思?當你說「java文件」你指的是XML佈局文件? – PeteH