У меня есть просмотрщик внутри в действии. Эта деятельность запускает три фрагментации (не с вкладками), так как создаются три разных фрагмента расширений класса. Он отлично работает с горизонтальной прокруткой между фрагментом. Теперь я хочу использовать collapsingToolbar с отдельным отображением изображения в фрагменте. активность - наличие ViewPager, Fragment1 XML, имеющий collapsingToolbar, Fragement1 также 'content_launch.xml' Fragement1 класс - панель инструментов добавлена, но при выборке (CollapsingToolbar объект он возвращает нульCollapsingToolbarLayout внутри Фрагмент, возвращающий нуль
активность XML, как показано ниже:
<LinearLayout 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:orientation="vertical" tools:context=".activity.LaunchActivity">
<android.support.v4.view.ViewPager
android:id="@+id/launchpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
.
Activity
Класс для запуска viewpager
ViewPager viewPager = (ViewPager) findViewById(R.id.launchpager);
viewPager.setAdapter(new LaunchAdapter(getSupportFragmentManager
(),getApplicationContext()));
Fragement1 XML
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/quote_coordinator"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:id="@+id/quote_appbar"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/quote_collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim ="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/quote_backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode ="parallax"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal" android:orientation="vertical">
<TextView android:id="@+id/quote_main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_title"
android:textColor="@android:color/white"
android:textSize="@dimen/main_title"/>
<TextView android:id="@+id/quote_sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_sub_title"
android:textColor="@android:color/white"
android:textSize="@dimen/main_sub_title"/>
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/quote_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_quote"/>
</android.support.design.widget.CoordinatorLayout>
Fragment1 Класс:
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar quoteToolbar = (Toolbar) getActivity().findViewById(R.id.quote_toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(quoteToolbar);
final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) getActivity().findViewById(R.id.quote_collapsing_toolbar);
}
объект collapsingToolbar возвращается как нуль, не в состоянии найти какие-либо предложения, кто-то может предложить возможный способ получить объект ..
благодарит MilanNz, применяя его, я получаю необратимые типы для просмотра appcompatactivity. – prasoons