webentwicklung-frage-antwort-db.com.de

So erhalten Sie eine Vorschau unter Viewpager in CoordinatorLayout

Im Moment erscheint AdView innerhalb von ViewPager und blockiert somit den Inhalt in der App. Wie bekomme ich, dass die AdView unter der ViewPager erscheint und nicht im Inneren.

Ich habe versucht, die AdView in eine RelativeLayout unterhalb der ViewPager zu setzen, aber die AdView wird dann überhaupt nicht angezeigt. 

<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:tools="http://schemas.Android.com/tools"
xmlns:app="http://schemas.Android.com/apk/res-auto"
xmlns:ads="http://schemas.Android.com/apk/res-auto"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="vertical"
tools:context="com.candyx.testapp.Activity">

<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/main_content"
    Android:layout_width="match_parent"
    Android:layout_height="match_parent">

    <Android.support.design.widget.AppBarLayout
        Android:layout_width="match_parent"
        Android:layout_height="wrap_content"
        Android:background="@drawable/main_button_background">

        <Android.support.v7.widget.Toolbar
            xmlns:Android="http://schemas.Android.com/apk/res/Android"
            Android:id="@+id/toolbar"
            Android:layout_width="match_parent"
            Android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <Android.support.design.widget.TabLayout
            Android:id="@+id/tabs"
            Android:layout_width="match_parent"
            Android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorTabIndicator"
            app:tabIndicatorHeight="3dp"/>

    </Android.support.design.widget.AppBarLayout>


    <Android.support.v4.view.ViewPager
        Android:id="@+id/viewPager"
        Android:layout_width="match_parent"
        Android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <com.google.Android.gms.ads.AdView
        Android:id="@+id/adView"
        Android:layout_width="match_parent"
        Android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        Android:layout_gravity="center|bottom"/>

</Android.support.design.widget.CoordinatorLayout>

</LinearLayout>
34
Jacques Krause

Sie können ViewPager und AdView in RelativeLayout hinzufügen und Android:layout_above="@+id/adView"-Eigenschaft für ViewPager angeben, damit adView den Inhalt von ViewPager nicht blockiert.

<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    xmlns:tools="http://schemas.Android.com/tools"
    xmlns:app="http://schemas.Android.com/apk/res-auto"
    xmlns:ads="http://schemas.Android.com/apk/res-auto"
    Android:layout_width="match_parent"
    Android:layout_height="match_parent"
    tools:context="com.candyx.testapp.Activity">

    <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/main_content"
        Android:layout_width="match_parent"
        Android:layout_height="match_parent"
        Android:layout_above="@+id/adView">

        <Android.support.design.widget.AppBarLayout
            Android:layout_width="match_parent"
            Android:layout_height="wrap_content"
            Android:background="@drawable/main_button_background">

            <Android.support.v7.widget.Toolbar
                xmlns:Android="http://schemas.Android.com/apk/res/Android"
                Android:id="@+id/toolbar"
                Android:layout_width="match_parent"
                Android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"/>

            <Android.support.design.widget.TabLayout
                Android:id="@+id/tabs"
                Android:layout_width="match_parent"
                Android:layout_height="wrap_content"
                app:tabMode="scrollable"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/colorTabIndicator"
                app:tabIndicatorHeight="3dp"/>

        </Android.support.design.widget.AppBarLayout>

        <Android.support.v4.view.ViewPager
            Android:id="@+id/viewPager"
            Android:layout_width="match_parent"
            Android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </Android.support.design.widget.CoordinatorLayout>

    <com.google.Android.gms.ads.AdView
        Android:id="@id/adView"
        Android:layout_width="match_parent"
        Android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        Android:layout_gravity="center|bottom"
        Android:layout_alignParentBottom="true"/>

</RelativeLayout>
95
Abhishek V

Fügen Sie ViewPager und Adview wie folgt in ein weiteres LinearLayout ein:

    <LinearLayout 
        Android:layout_width="match_parent"
        Android:layout_height="match_parent"
        Android:orientation="vertical">
     <Android.support.v4.view.ViewPager
            Android:id="@+id/viewPager"
            Android:layout_width="match_parent"
            Android:layout_height="0dp"
            Android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            Android:layout_weight="1"/>

        <com.google.Android.gms.ads.AdView
            xmlns:ads="http://schemas.Android.com/apk/res-auto"
            Android:id="@+id/adView"
            Android:layout_width="match_parent"
            Android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id"
            Android:layout_gravity="center|bottom"
            />
    </LinearLayout>
3
Audumbar

Das funktionierte für mich: Fügen Sie einfach die App in den ViewPager ein: layout_behavior:

<Android.support.v4.view.ViewPager
    Android:layout_width="match_parent"
    Android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
2
Nick Stampoulis

wie ich auf echtem Gerät teste, funktioniert das für mich: Fix Height Declared On Child `

<Android.support.design.widget.CoordinatorLayout
    Android:id="@+id/htab_maincontent"
    Android:layout_width="match_parent"
    Android:layout_above="@+id/PanelView"
    Android:layout_height="match_parent">
    <!--Android:fitsSystemWindows="false">-->

    <Android.support.design.widget.AppBarLayout
        Android:id="@+id/htab_appbar"
        Android:layout_width="match_parent"
        Android:layout_height="wrap_content"
        Android:fitsSystemWindows="true"
        Android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <Android.support.design.widget.CollapsingToolbarLayout
            Android:id="@+id/htab_collapse_toolbar"
            Android:layout_width="match_parent"
            Android:layout_height="256dp"
            Android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                Android:id="@+id/htab_header"
                Android:layout_width="match_parent"
                Android:layout_height="match_parent"
                Android:background="@drawable/title_panel_main"
                Android:fitsSystemWindows="true"
                Android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <Android.support.v7.widget.Toolbar
                Android:id="@+id/htab_toolbar"
                Android:layout_width="match_parent"
                Android:layout_height="104dp"
                Android:gravity="top"
                Android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleMarginTop="13dp" />

            <Android.support.design.widget.TabLayout
                Android:id="@+id/htab_tabs"
                Android:layout_width="match_parent"
                Android:layout_height="?attr/actionBarSize"
                Android:layout_gravity="bottom"
                app:tabIndicatorColor="@Android:color/white" />
        </Android.support.design.widget.CollapsingToolbarLayout>
    </Android.support.design.widget.AppBarLayout>


    <Android.support.v4.view.ViewPager
        Android:id="@+id/tab_viewpager"
        Android:layout_width="match_parent"
        Android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</Android.support.design.widget.CoordinatorLayout>


<LinearLayout
    Android:id="@+id/PanelView"
    Android:layout_width="match_parent"
    Android:layout_height="70dp"
    Android:orientation="horizontal"
    Android:padding="7dp"
    Android:layout_alignParentBottom="true"
    Android:visibility="visible">



    <TextView
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_marginRight="10dp"
         />
</LinearLayout>
</RelativeLayout>`

Hoffe, helfe dir

0
FxRi4

Ich habe die Antwort von @AvishekV ausprobiert, aber das hat mein Problem nicht gelöst. Aber ich habe THE IDEA genommen, um CoordinatorLayout und Adview in ein übergeordnetes Layout zu setzen was in meinem Fall ConstraintLayout war. Unten ist die Struktur

<Android.support.constraint.ConstraintLayout 
    xmlns:Android="http://schemas.Android.com/apk/res/Android"
    xmlns:ads="http://schemas.Android.com/apk/res-auto"
    xmlns:app="http://schemas.Android.com/apk/res-auto"
    Android:layout_width="match_parent"
    Android:layout_height="match_parent">

   <Android.support.design.widget.CoordinatorLayout
       Android:id="@+id/content"
       Android:layout_width="0dp"
       Android:layout_height="0dp"
       Android:fitsSystemWindows="true"
       app:layout_constraintBottom_toTopOf="@+id/adView"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent">

        <Android.support.design.widget.AppBarLayout>
           //CollapsingToolbarLayout
           //ConstraintLayout, if you need to put anything inside collpasingtoolbar
           //Toolbar
           //TabLayout
        </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" />
</Android.support.design.widget.CoordinatorLayout>

<com.google.Android.gms.ads.AdView
    Android:id="@+id/adView"
    Android:layout_width="wrap_content"
    Android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="your adunit id"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

</Android.support.constraint.ConstraintLayout>
0
Sadman