2016-06-24 8 views
0

私はスクロールビューが1つ必要です。スクロールビュー内に私は1つのリストビューを持っています。リストビューの行項目には1つのframlayoutがあります。私は広告が準備ができたら、フレームレイアウトにnativeexpreesviewを追加しています。スクロールビューが動作していないリストビューの生の項目に動的にビューを追加します。アンドロイド

広告がロードされていないときにリストに10個のアイテムがある場合は問題ありませんが、広告が読み込まれたときにフレームレイアウトに追加するために高さを占めますロードされる。

しかし、私はよく広告として全体の項目にスクロール

マイacivity'slayoutが

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/svStrategy" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/app_bg" 
    android:scrollbars="none"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:descendantFocusability="blocksDescendants" 
     android:orientation="vertical"> 


     <LinearLayout 
      android:id="@+id/lytBanner" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/list_selector" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="5dp" 
       android:layout_gravity="center" 

       android:text="@string/str_use_spells_best" 
       android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" 
       android:textColor="@android:color/white" /> 

      <ImageView 
       android:id="@+id/ivBanner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:adjustViewBounds="true" /> 
     </LinearLayout> 



     <com.example.SummonersWar.classes.NestedListView 
      android:id="@+id/lvStrategy" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="10dp" 
      android:cacheColorHint="#00000000" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="10dp" 
      android:fadingEdge="none" 
      android:focusable="false" 
      android:scrollbars="none" /> 

    </LinearLayout> 

</ScrollView> 

の下Nestedlistview

のRow_layout
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/lytStrategyRow" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/list_selector" 
     android:orientation="horizontal" 

     android:weightSum="2"> 

     <ImageView 
      android:id="@+id/ivStrategyIcon" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1.4" 
      android:scaleType="fitXY" /> 

     <TextView 
      android:id="@+id/tvStrategyTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_margin="5dp" 
      android:layout_weight="0.6" 
      android:ellipsize="end" 
      android:maxLines="4" 
      android:minLines="4" 


      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" 
      android:textColor="@android:color/white" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/rlads" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/lytStrategyRow" 
     android:orientation="vertical" 
     android:visibility="gone"> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="10dp" 
      android:background="@android:color/transparent" /> 

     <FrameLayout 
      android:id="@+id/fr_adview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"></FrameLayout> 
    </LinearLayout> 
</RelativeLayout> 

である私は、プログラム時に広告framlayoutするNativeexpressviewを追加していたいですが読み込まれます。広告が.soがロードされたときに

public class NestedListView extends ListView implements OnScrollListener // OnTouchListener 
{ 

    private int listViewTouchAction; 
    private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 100; 

    public NestedListView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     listViewTouchAction = -1; 
     setOnScrollListener(this); 
     // setOnTouchListener(this); 
    } 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, 
         int visibleItemCount, int totalItemCount) { 
     if (getAdapter() != null 
       && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) { 
      if (listViewTouchAction == MotionEvent.ACTION_MOVE) { 
       scrollBy(0, -1); 
      } 
     } 
    } 

    @Override 
    public void onScrollStateChanged(AbsListView view, int scrollState) { 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 

     int newHeight = 0; 
     final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 
     int heightSize = MeasureSpec.getSize(heightMeasureSpec); 
     if (heightMode != MeasureSpec.EXACTLY) { 
      ListAdapter listAdapter = getAdapter(); 
      if (listAdapter != null && !listAdapter.isEmpty()) { 
       int listPosition = 0; 
       for (listPosition = 0; listPosition < listAdapter.getCount() 
         && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) { 
        View listItem = listAdapter.getView(listPosition, null, 
          this); 
        // now it will not throw a NPE if listItem is a ViewGroup 
        // instance 
        if (listItem instanceof ViewGroup) { 
         listItem.setLayoutParams(new LayoutParams(
           LayoutParams.WRAP_CONTENT, 
           LayoutParams.WRAP_CONTENT)); 
        } 
        listItem.measure(widthMeasureSpec, heightMeasureSpec); 
        newHeight += listItem.getMeasuredHeight(); 

       } 
       newHeight += getDividerHeight() * listPosition; 
       newHeight += getPaddingBottom() + getPaddingTop(); 
      } 
      if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) { 
       if (newHeight > heightSize) { 
        newHeight = heightSize; 
       } 
      } 
     } else { 
      newHeight = getMeasuredHeight(); 
     } 
     setMeasuredDimension(getMeasuredWidth(), newHeight); 

    }} 

以下

私nestedlistviewはので、私の問題は、リストの高さのみscrollviewがスクロールである私は、広告でリスト全体をスクロールするために、今何をすべき私を助けてください?

答えて

0
import android.content.Context; 
import android.util.AttributeSet; 
import android.view.MotionEvent; 
import android.view.ViewParent; 
import android.widget.ScrollView; 

public class VerticalScrollview extends ScrollView { 

public VerticalScrollview(Context context) { 
    super(context); 
} 

public VerticalScrollview(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) 
{ 
    super(context, attrs, defStyle); 
} 

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    final int action = ev.getAction(); 
    switch (action) { 
     case MotionEvent.ACTION_DOWN: 
      super.onTouchEvent(ev); 
      break; 

     case MotionEvent.ACTION_MOVE: 
      return false; // redirect MotionEvents to ourself 

     case MotionEvent.ACTION_CANCEL: 
      super.onTouchEvent(ev); 
      break; 

     case MotionEvent.ACTION_UP: 
      return false; 

     default: 
      break; 
    } 

    return false; 
} 

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    super.onTouchEvent(ev); 
    return true; 
} 

}

+0

使用はあなたのレイアウトファイルでカスタムscrollviewを設定し、それが適切な – Chetna

+0

を働く私は、XMLで設定@Chetna – sunita

+0

XMLファイル – Chetna

関連する問題