2017-11-08 1 views
1

나는 안드로이드 프로그래밍에 익숙하지 않으며 아직 많은 것을 알지 못합니다. 여기서 내가 성취하고자하는 것은 이와 같은 것입니다. 사용자가 인터넷에 연결되어 있지 않으면 광고가 보이지 않거나 어떤 이유로 광고가로드되지 않으면 광고가 표시되지 않습니다. 그러나 레이아웃은 광고 공간이 비어있는 것과 동일한 의미를 유지합니다. 내가 한 것은 상대 레이아웃 내부에서 광고보기를 왜곡 한 다음 광고가로드되었는지 또는 레이아웃의 가시성이 변경되는지 확인하는 기능을 만들었습니다. 광고가 보이지 않을 때 빈 공간 문제를 해결하고 해결하는 것 같습니다. 하중. 그러나 이것이 이것이 최선의 방법은 아니며 더 좋은 방법이 있어야한다고 생각합니다. 사용자가 어떤 인터넷 연결이없는 경우제약 레이아웃 admob issue

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.admobTest.MainActivity" 
    tools:layout_editor_absoluteY="81dp"> 

    <Button 
     android:id="@+id/btnExit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 


     android:layout_marginEnd="8dp" 
     android:text="@string/btnExit" 
     ads:layout_constraintBaseline_toBaselineOf="@+id/btnViewBuildProp" 
     ads:layout_constraintEnd_toEndOf="parent" /> 

    <Button 
     android:id="@+id/btnViewBuildProp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:layout_marginStart="8dp" 
     android:text="@string/btnViewBuildProp" 
     ads:layout_constraintBottom_toTopOf="@+id/relativeAdsLayout" 
     ads:layout_constraintStart_toStartOf="parent" /> 

/> 

    <TextView 
     android:id="@+id/txvStatus" 
     android:layout_width="368dp" 
     android:layout_height="0dp" 
     android:text="TextView" 

     tools:layout_editor_absoluteX="8dp" 
     tools:layout_editor_absoluteY="8dp" /> 


    <TextView 
     android:id="@+id/txvDeviceInfo" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:text="TextView" 
     ads:layout_constraintBottom_toTopOf="@+id/btnViewBuildProp" 
     ads:layout_constraintEnd_toEndOf="parent" 
     ads:layout_constraintStart_toStartOf="parent" 
     ads:layout_constraintTop_toBottomOf="@+id/txvStatus" /> 

    <RelativeLayout 
     android:id="@+id/relativeAdsLayout" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:visibility="gone" 
     ads:layout_constraintBottom_toBottomOf="parent" 
     ads:layout_constraintEnd_toEndOf="parent" 
     ads:layout_constraintStart_toStartOf="parent" 
     ads:layout_constraintTop_toBottomOf="@+id/btnExit"> 


     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      ads:adSize="@string/adSize" 
      ads:adUnitId="@string/adUnitId" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintEnd_toEndOf="parent" 
      app:layout_constraintStart_toStartOf="parent" 
      tools:layout_editor_absoluteY="457dp" /> 

    </RelativeLayout> 

</android.support.constraint.ConstraintLayout> 

MainActivity.java에만 해당 비트

public class MainActivity extends AppCompatActivity { 
    private AdView mAdView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     showAds(true); // this displays the ads 

     } 
    private void showAds(Boolean doShowAds) { 
     RelativeLayout relativeAdsLayout = findViewById(R.id.relativeAdsLayout); 

     if (doShowAds.equals(true)) { 
      mAdView = findViewById(R.id.adView); 
      AdRequest adRequest = new AdRequest.Builder().build(); 
      mAdView.loadAd(adRequest); 
      relativeAdsLayout.setVisibility(View.VISIBLE); 

     } else if (doShowAds.equals(false)) { 
      relativeAdsLayout.setVisibility(View.GONE); 
     } 
    } //end showAds 
} //end class 
+0

왜 아래로 투표가없는 경우는? 아무 이유없이 투표를 남기지 말고 의견을 남기십시오. – arifur

+0

현재 해결해야 할 약점은 무엇입니까? 이것을 해결하기 위해 admob API 메소드를 찾고 있습니까? 사이드 노트는 왜'boolean' 프리미티브 대신에'Boolean' 객체를 사용하고 있습니까? – Jon

+0

이 경우 admob API가 있으면 yes입니다. 두 번째 질문에 대한 답은 제가 멍청하기 때문입니다. – arifur

답변

1

전혀로 AdView를 추가하지 마십시오. 사용자에게 적절한 인터넷 연결이 없다는 것을 알고 있다면 광고 요청을 피해야합니다.

광고 요청이 실패하면 레이아웃에서 AdView를 삭제하거나 원하는대로 다른 추가 요청을 시도 할 수 있습니다. 또한 일부 진전 또는 다른 배경보기 (또는 이미지 등 진행)를 추가 할 수 있습니다

, 광고로드를 책략 또는 사용자가 어떤 인터넷

+0

많은 앱에서 사용자가 인터넷을 가지고 있지 않을 때 레이아웃이 전체 화면으로 표시되어 광고를 위해 남겨진 공간을 채우는 것으로 나타났습니다. 사용자가 인터넷을 사용하면 광고가 표시되고 레이아웃이 올라가 광고 공간을 확보합니다. 나는 비슷한 것을하고 싶었다. 그게 내가 광고를 숨기고 결과적으로 레이아웃을 확장하는 함수를 만든 이유입니다. 더 좋은 해결책이 있다면 생각하고있었습니다. 기본 동작 스크린 샷 : [imgur] (https://imgur.com/a/wFySk) – arifur