我通过添加android:layout_marginTop="112dp"
来实现这一点,有没有其他方法让我的ImageView在AppBarLayout
下方,就像我们在RelativeLayout中一样?
此外,我希望这个ImageView
具有与AppBarLayout
相同的阴影,因此图像将显示为AppBarLayout的一部分。
我希望TextView
出现在LinearLayout
的图像下方。
主要活动XML
<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>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="112dp"
android:orientation="horizontal">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/under_tabs_triangle"/>
</LinearLayout>
<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" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
片段主XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dexbyte.player.MainActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
请检查此图片:
此外,我希望此ImageView具有与AppBarLayout相同的阴影,因此图像将显示为AppBarLayout的一部分。
它可以通过在其中添加CardView
和ImageView
或其他方式来实现,但是,如果你想要两者都有阴影,你可能需要删除AppBarLayout
阴影,因为ImageView
和AppBarLayout
之间会有阴影看起来不太好看。
我希望
TextView
出现在LinearLayout
的图像下方。
TextView
实际上显示在正确的位置,因为你已添加:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
到ViewPager
。所以,一切都很好。要实现您的目标,您可以添加:
android:layout_marginTop="30dp" <!-- Or more ... -->
到TextViewget
完成它。