如何在活动视图和tablayout之间设置视图?

时间:2017-07-19 12:21:59

标签: android android-tablayout

我有一个TabLayout。在我设置TabLayout的MainActivity中,我还有三个按钮和底部的横幅(因此这些按钮和横幅位于tablayout的前面)。我想要做的是将ImageView准确地放在按钮/横幅和标签之间。我怎样才能做到这一点?

enter image description here

这是布局的图片,我希望视图完全位于按钮和布局之间的中心。

代码main_activity:

<?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"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.tomhogenkamp.NeonDiscoLight.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <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" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

        <LinearLayout
            android:layout_above="@id/adView"
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="3">

            <Button
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="settings"
                android:id="@+id/setting"/>

            <Button
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="start"
                android:id="@+id/start"/>

            <Button
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="rate"
                android:id="@+id/rate"/>

        </LinearLayout>

    </RelativeLayout>

和片段代码:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background">

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/viewStrobe"/>

    <ImageView
        android:layout_above="@+id/linearLayout"
        android:id="@+id/imageViewStroboscope"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerInside"
        android:adjustViewBounds="true"/>

</RelativeLayout>

0 个答案:

没有答案
相关问题