从Intent返回到“主要活动”后,AdView标语会通过键盘更改位置

时间:2019-03-21 10:50:24

标签: android android-intent android-constraintlayout

我的AdView标语限制在父级底部。只要我不启动我的Intent SQLView,就没有问题。调用SQLView并返回到Main Activity之后,横幅将根据键盘移动。请参考所附图片。在下面附加我的代码的一部分,如果需要更多部分,请告诉我,我将相应地添加。谢谢! Start of app

Before calling SQLView

After calling SQLView and returning to Main Activity

主要活动

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

    btnView = findViewById(R.id.buttonView);
    bannerAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    bannerAdView.loadAd(adRequest);


    btnView.setOnClickListener(this);

}

@Override
public void onClick(View arg0) {
    switch (arg0.getId()){
        case R.id.buttonSetBudget:
            setBudgetDialog();
            break;
        case R.id.buttonSave:
            ...                
            break;
        case R.id.buttonView:
            Intent i = new Intent(this, SQLView.class);
            startActivity(i);
            break;
        case R.id.buttonExport:
    ...
            break;
    }

}

SQLView

public class SQLView extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    Button backButton = findViewById(R.id.buttonBack);
...

    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}
}

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:background="@color/colorColumnOne"
    android:orientation="vertical"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    tools:context=".MainActivity">

...

<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_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="8dp"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    ads:layout_constraintBottom_toBottomOf="parent"
    ads:layout_constraintEnd_toEndOf="parent"
    ads:layout_constraintHorizontal_bias="0.5"
    ads:layout_constraintStart_toStartOf="parent">
</com.google.android.gms.ads.AdView>

1 个答案:

答案 0 :(得分:0)

  

在AndroidMainfest.xml中将windowSoftInputMode设置为AdjustPan

 <activity
   android:name="com.companyname.applicationname"
   android:windowSoftInputMode="adjustPan"> 
</activity>