Сделайте все фрагменты выше баннерной рекламы - PullRequest
0 голосов
/ 01 января 2019

У меня есть 3 Fragments в MainActivity, где они все отображаются, в макете MainActivity у меня есть рекламный баннер под индикатором выполнения (оба расположены внизу), так что я хочу, чтобы весь фрагмент былРазмещено над баннером и индикатором прогресса, есть ли какое-либо решение ??

Это полный макет Activity_main (с решением, которое я опишу в разделе комментариев):

<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary_color"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.android.miwok.MainActivity"
    tools:openDrawer="start">



        <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"
            tools:context=".MainActivity">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"

                >

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/primary_color"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <Button
                    android:id="@+id/more_toolbar"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="end"
                    android:layout_marginEnd="8dp"
                    android:background="@drawable/thumbsuo" />
            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                style="@style/CategoryTab"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>


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


            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"

                />


                <ProgressBar
                    android:id="@+id/progressBarParent"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:layout_width="match_parent"
                    android:layout_height="10dp"
                    android:layout_marginBottom="2dp"

                    />

                <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="SMART_BANNER"
                    ads:adUnitId="ca-app-pub-3940256099942544/6300978111">

                </com.google.android.gms.ads.AdView>
            </LinearLayout>


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


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/primary_color"
        app:headerLayout="@layout/nav_header"
        app:itemIconTint="@color/text_drawer_color"
        app:itemTextColor="@color/text_drawer_color"
        app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>

И этополный макет фрагмента:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/tan_background"
>



<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:layout_margin="4dp"

    >

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:background="@color/tan_background"
    android:divider="@color/tan_background"
    android:dividerHeight="8dp"
    android:drawSelectorOnTop="true"
    android:focusable="true"
    android:orientation="vertical"
    android:nestedScrollingEnabled="true"

  />
</android.support.v4.widget.NestedScrollView>

Спасибо за помощь :)

1 Ответ

0 голосов
/ 01 января 2019

Теперь, когда вы разместили больше кода, я вижу, что это даже проще, чем я думал.Вам не нужно RelativeLayout вообще.Вы можете использовать один LinearLayout, и ваш ViewPager должен иметь вес 1, чтобы он заполнял пустое пространство.Вот код (не проверен, поэтому может иметь опечатки).

<android.support.v4.widget.DrawerLayout 
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary_color"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.android.miwok.MainActivity"
    tools:openDrawer="start">

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/primary_color"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <Button
            android:id="@+id/more_toolbar"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="right"
            android:layout_marginRight="8dp"
            android:background="@drawable/thumbsuo"

        />

    </android.support.v7.widget.Toolbar>


    <android.support.design.widget.TabLayout

        android:id="@+id/tabs"
        style="@style/CategoryTab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

    <ProgressBar
        android:id="@+id/progressBarParent"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:layout_marginBottom="2dp"

    />

    <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="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">

    </com.google.android.gms.ads.AdView>

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/primary_color"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/text_drawer_color"
    app:itemTextColor="@color/text_drawer_color"
    app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout> 
...