나는 안드로이드 프로그래밍에 익숙하지 않으며 아직 많은 것을 알지 못합니다. 여기서 내가 성취하고자하는 것은 이와 같은 것입니다. 사용자가 인터넷에 연결되어 있지 않으면 광고가 보이지 않거나 어떤 이유로 광고가로드되지 않으면 광고가 표시되지 않습니다. 그러나 레이아웃은 광고 공간이 비어있는 것과 동일한 의미를 유지합니다. 내가 한 것은 상대 레이아웃 내부에서 광고보기를 왜곡 한 다음 광고가로드되었는지 또는 레이아웃의 가시성이 변경되는지 확인하는 기능을 만들었습니다. 광고가 보이지 않을 때 빈 공간 문제를 해결하고 해결하는 것 같습니다. 하중. 그러나 이것이 이것이 최선의 방법은 아니며 더 좋은 방법이 있어야한다고 생각합니다. 사용자가 어떤 인터넷 연결이없는 경우제약 레이아웃 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
왜 아래로 투표가없는 경우는? 아무 이유없이 투표를 남기지 말고 의견을 남기십시오. – arifur
현재 해결해야 할 약점은 무엇입니까? 이것을 해결하기 위해 admob API 메소드를 찾고 있습니까? 사이드 노트는 왜'boolean' 프리미티브 대신에'Boolean' 객체를 사용하고 있습니까? – Jon
이 경우 admob API가 있으면 yes입니다. 두 번째 질문에 대한 답은 제가 멍청하기 때문입니다. – arifur