ScrollView内にAdmobを配置したところ、表示はされるのですが広告の更新のタイミングで、勝手にスクロール位置が変わってしまいます。
勝手にスクロールさせないための方法がわからず質問させていただきました。
以下はレイアウトのxmlとjavaの広告を読み込んでいるonCreate部分となります。
lang
1<?xml version="1.0" encoding="utf-8"?> 2<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:id="@+id/PanelPlaceholder"> 6 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 7 xmlns:ads="http://schemas.android.com/apk/res-auto" 8 xmlns:tools="http://schemas.android.com/tools" 9 android:id="@+id/layout01" 10 android:layout_width="match_parent" 11 android:layout_height="match_parent" 12 android:orientation="vertical"> 13 14 <android.support.v7.widget.Toolbar 15 android:id="@+id/tool_bar" 16 android:layout_height="wrap_content" 17 android:layout_width="match_parent" 18 android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 19 android:minHeight="?attr/actionBarSize" 20 android:background="@color/somocolorres"> 21 </android.support.v7.widget.Toolbar> 22 23 <ScrollView 24 android:id="@+id/scroll_view01" 25 android:layout_width="match_parent" 26 android:layout_height="0dp" 27 android:layout_weight="1"> 28 <LinearLayout 29 android:id="@+id/mainPane" 30 android:layout_width="fill_parent" 31 android:layout_height="wrap_content" 32 android:orientation="vertical"> 33 <com.google.android.gms.ads.AdView 34 android:id="@+id/ad_view" 35 android:layout_width="wrap_content" 36 android:layout_height="wrap_content" 37 android:layout_gravity="center_horizontal" 38 ads:adSize="BANNER" 39 ads:adUnitId="@string/ad_unit_id" /> 40 <TextView 41 android:id="@+id/text01" 42 android:layout_width="wrap_content" 43 android:layout_height="wrap_content" 44 android:textSize="13sp" 45 android:padding="2dp" 46 android:layout_margin="2dp"/> 47 <!-- その他TextViewなどが続くが省略 --> 48 </LinearLayout> 49 </ScrollView> 50 </LinearLayout> 51</FrameLayout>
lang
1protected void onCreate(Bundle savedInstanceState) { 2 super.onCreate(savedInstanceState); 3 setContentView(R.layout.hogehoge_layout); 4 5 //TextViewへのセットなど画面表示処理(略) 6 7 //広告の表示 8 AdView adView = (AdView) findViewById(R.id.ad_view); 9 AdRequest adRequest = new AdRequest.Builder().build(); 10 adView.loadAd(adRequest); 11} 12コード
開発ターゲットは
minSdkVersion 14
targetSdkVersion 22
としております。
また、onCreate時にScrollViewに対し、OnTouchLitenerを追加してタッチ時以外はスクロール無効としてみましたが、効果がありませんでした。
lang
1 ScrollView sv = (ScrollView) findViewById(R.id.scroll_view01); 2 sv.setOnTouchListener(new View.OnTouchListener(){ 3 @Override 4 public boolean onTouch(View v, MotionEvent event){ 5 if(event.getAction() == MotionEvent.ACTION_MOVE) { 6 return false; 7 }else{ 8 return true; 9 } 10 } 11 }); 12コード
他に必要な情報等ございましたら追記いたします。
どうぞよろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。