【发布时间】:2017-04-09 06:46:53
【问题描述】:
我正在尝试创建如下截图所示的布局:
下面是相同的布局 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-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".DetailActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/iv_movie_backdrop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/str_movie_backdrop_image"
android:scaleType="fitXY" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/cv_poster_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="@dimen/card_elevation"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<ImageView
android:id="@+id/iv_movie_poster"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:contentDescription="@string/str_movie_poster"
android:padding="@dimen/poster_padding"
android:scaleType="fitXY"
android:src="@drawable/not_found" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/cv_poster_image"
android:orientation="vertical">
<TextView
android:id="@+id/tv_movie_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="64dp"
android:layout_marginStart="8dp"
android:padding="@dimen/poster_padding"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/black"
android:textStyle="bold"
tools:text="Spider Man and Iron Man" />
<TextView
android:id="@+id/tv_release_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:drawablePadding="@dimen/poster_padding"
android:drawableStart="@drawable/ic_date_range_black_24dp"
android:gravity="start"
android:padding="@dimen/poster_padding"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@android:color/black"
tools:text="March, 2017" />
<TextView
android:id="@+id/tv_rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:drawablePadding="@dimen/poster_padding"
android:drawableStart="@drawable/ic_star_black_24dp"
android:gravity="start"
android:padding="@dimen/poster_padding"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@android:color/black"
tools:text="7.1" />
<TextView
android:id="@+id/tv_genre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:padding="@dimen/poster_padding"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@android:color/black"
android:textStyle="italic"
tools:text="Horror | Comedy | Drama" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cv_poster_image"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
style="@style/CategoryTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_favorite_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
我的问题是带有 ViewPager 的 TabLayout,我无法使用任何 FragmentLayout 为 ViewPager 充气。如果相同的 TabLayout 和 ViewPager 我将它复制到一个新的布局中,我可以为 FragmentLayout 充气,甚至滑动也可以。
是不是因为我在 Activity 中只能有 TabLayout 和 ViewPageralone 而不能在它们之上有任何其他视图。
【问题讨论】:
-
您的浏览器片段中有元素吗?
-
我的片段布局有一个 TextView,其文本设置为“1”。
标签: android android-layout android-viewpager android-xml android-tablayout