简体   繁体   English

为什么我的横幅没有出现在 Linearlayout 中?

[英]why doesn't my banner appear in Linearlayout?

I am using relative layout in linear layout.My banner appears on the design screen, but no ads appear when I run my application.I looked at many examples but I could not find.My application was horizontal before now I'm designing vertically.Previously I was using Relativelayout then my banner was working.Here my code;我在线性布局中使用相对布局。我的横幅出现在设计屏幕上,但是当我运行我的应用程序时没有出现广告。我看了很多例子,但我找不到。我的应用程序以前是水平的,现在我正在垂直设计。以前我使用的是Relativelayout,然后我的横幅正在工作。这是我的代码;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
   android:orientation="vertical"
   android:weightSum="12"
   android:background="#fffdd0">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="2">
    <RelativeLayout
        android:layout_width="150dp"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true">
        <Button
            android:id="@+id/btn_double"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentStart="true"
            android:background="@drawable/xx"
            android:layout_marginTop="15dp"/>
        <Button
            android:id="@+id/btn_yariyariya"
            android:layout_width="47dp"
            android:layout_height="47dp"
            android:background="@drawable/fiftyfifty"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="15dp"/>
        <Button
            android:id="@+id/btn_skip"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_alignParentEnd="true"
            android:background="@drawable/skip"
            android:layout_marginTop="15dp"/>
        <TextView
            android:id="@+id/tv_countdown2x"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:layout_alignParentStart="true"
            android:textColor="@color/colorPrimary"
            android:layout_below="@+id/btn_double" />
        <TextView
            android:id="@+id/tv_countdown50"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:layout_centerHorizontal="true"
            android:textColor="@color/colorPrimary"
            android:layout_below="@+id/btn_yariyariya"/>
        <TextView
            android:id="@+id/tv_countdownNext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:layout_alignParentEnd="true"
            android:textColor="@color/colorPrimary"
            android:layout_below="@+id/btn_skip"/>
        <TextView
            android:id="@+id/tv_countdown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:text="00:30"
            android:textSize="30sp"
            android:layout_centerHorizontal="true"
            android:textColor="@color/colorPrimary"
            android:layout_marginTop="85dp" />
        <FrameLayout
            android:id="@+id/container_pop_up"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="16dp" />
    </RelativeLayout>
    <TextView
        android:id="@+id/tv_countdown1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:layout_marginStart="40dp"
        android:layout_marginTop="60dp"
        android:textColor="@color/colorPrimary"/>
    <Button
        android:id="@+id/btn_kalp1"
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:background="@drawable/kalp"
        android:layout_alignParentStart="true"
        android:layout_marginStart="30dp"
        android:layout_marginTop="15dp"/>
    <Button
        android:id="@+id/btn_satinal"
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:layout_marginStart="200dp"
        android:onClick="satinalMain"
        android:background="@drawable/satinal"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="30dp"
        android:layout_marginTop="15dp"/>
    <TextView
        android:id="@+id/tv_kalp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="5"
        android:textColor="@color/colorPrimary"
        android:layout_alignParentStart="true"
        android:layout_marginTop="25dp"
        android:layout_marginStart="84dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10sp"
        android:text="X"
        android:textColor="@color/colorPrimary"
        android:layout_alignParentStart="true"
        android:layout_marginTop="35dp"
        android:layout_marginStart="77dp"/>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="3">
    <TextView
        android:id="@+id/tv_soru"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:fontFamily="@font/incee"
        android:gravity="center"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        android:textAlignment="gravity"
        android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="5"
    android:orientation="vertical">
    <Button
        android:id="@+id/btn_a"
        android:layout_width="260dp"
        android:layout_height="60dp"
        android:textColor="#000"
        android:background="@drawable/gradient"
        android:gravity="center"
        android:textAlignment="gravity"
        android:fontFamily="@font/incee"
        android:textSize="12sp"
        android:layout_centerHorizontal="true"/>
    <Button
        android:id="@+id/btn_b"
        android:layout_width="260dp"
        android:layout_height="60dp"
        android:layout_below="@+id/btn_a"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:background="@drawable/gradient"
        android:fontFamily="@font/incee"
        android:gravity="center"
        android:textAlignment="gravity"
        android:textColor="#000"
        android:textSize="12sp" />
    <Button
        android:id="@+id/btn_c"
        android:layout_width="260dp"
        android:layout_height="60dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/gradient"
        android:fontFamily="@font/incee"
        android:gravity="center"
        android:textAlignment="gravity"
        android:textColor="#000"
        android:textSize="12sp"
        android:layout_below="@+id/btn_b"
        android:layout_marginTop="5dp"/>
    <Button
        android:id="@+id/btn_d"
        android:layout_width="260dp"
        android:layout_height="60dp"
        android:textColor="#000"
        android:background="@drawable/gradient"
        android:gravity="center"
        android:textAlignment="gravity"
        android:fontFamily="@font/incee"
        android:textSize="12sp"
        android:layout_below="@+id/btn_c"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"/>
    <Button
        android:id="@+id/btn_infoA"
        android:layout_width="40dp"
        android:layout_height="45dp"
        android:background="@drawable/info"
        android:layout_centerVertical="true"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>
    <Button
        android:id="@+id/btn_gec"
        android:layout_width="65dp"
        android:layout_height="60dp"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:layout_marginEnd="1dp"
        android:background="@drawable/next"/>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1">
    <TextView
        android:id="@+id/tv_skor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:text="0"
        android:textColor="#000"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="25dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:textStyle="bold"
        android:text="SKOR :"
        android:textColor="#000"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="50dp"
        android:layout_marginBottom="5dp"/>
    <Button
        android:id="@+id/btn_reklam"
        android:layout_width="50dp"
        android:layout_height="45dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="5dp"
        android:background="@drawable/plus"
        android:onClick="startVideoAd"/>
    <TextView
        android:id="@+id/tv_kalp_kazan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="İzle Kazan"
        android:layout_alignParentStart="true"
        android:textSize="15sp"
        android:textStyle="bold"
        android:layout_alignParentBottom="true"
        android:fontFamily="@font/incee"
        android:textColor="#000"
        android:layout_marginStart="55dp"
        android:layout_marginBottom="5dp"/>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    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="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3101578796185185/4912585915">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

I think it's because the bannerview is lower than your screen!我认为这是因为bannerview低于您的屏幕! (Maybe you're using this layout for a fragment and your activity has a toolbar, am I right?) (也许您正在将这种布局用于片段并且您的活动有一个工具栏,对吗?)

Just put LinearLayout inside a ScrollView and see if it works.只需将LinearLayout放在ScrollView ,看看它是否有效。

Your layout design is not very well done, the buttons at the center (first RelativeLayout) are not constrained to the adjacent buttons, so they may overlap.你的布局设计不是很好,中间的按钮(第一个RelativeLayout)不受相邻按钮的限制,所以它们可能会重叠。

You should use a ConstraintLayout instead of RelativeLayout , the later is obsolete now.您应该使用ConstraintLayout而不是RelativeLayout ,后者现在已经过时了。

You have several items with wrap_content height inside a layout that you want to stretch vertically, which is contradictory.您在要垂直拉伸的布局中有几个具有wrap_content高度的项目,这是矛盾的。 This may cause views inside the inner RelativeLayouts to be hidden if they are smaller than the height.如果它们小于高度,这可能会导致内部 RelativeLayouts 中的视图被隐藏。

weightSum is a property that is rarely useful because weights are calculated automatically, you should simply know that two views with 1 and 1 with use 50% each, and if you add another with weight 2 it will have proportionally that weight. weightSum是一个很少有用的属性,因为权重是自动计算的,您应该只知道具有 1 和 1 的两个视图各使用 50%,如果添加另一个权重为 2 的视图,它将按比例获得该权重。 So it will end up 25%, 25% and 50%.所以它最终会是 25%、25% 和 50%。

There is no need to place the AdView inside a RelativeLayout if it is the only view there.如果它是唯一的视图,则无需将 AdView 放在 RelativeLayout 中。

If you want the banner to be always visible, then simply place a default height (either wrap_content or a given height in dps).如果您希望横幅始终可见,只需放置一个默认高度( wrap_content或以 dps 为单位的给定高度)。 The other views will use the remaining space to calculate the weight space.其他视图将使用剩余空间来计算weight空间。

I recommend you to first study how different Layouts work before attempting to build your screen layout.我建议您在尝试构建屏幕布局之前首先研究不同布局的工作原理。

On the other hand, the AdView requires some additional configuration on your end to become shown, because if you did not setup some campaign to be shown, the view won't display anything.另一方面,AdView 需要在您的一端进行一些额外的配置才能显示,因为如果您没有设置要显示的某些广告系列,该视图将不会显示任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM