2017-07-27 16 views
0

私は、私がrecyclerviewのサーバーからdataListを表示したい、そして、私がrecyclerViewの終わりまでスクロールするときに、progressbarを下に表示したいのですが、また、recycViewの間にAdsViewを追加しましたが、指定されたインデックス。Viewを表示すると、recyclerviewの項目と重複していますか?

コード: - itemView

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
card_view:cardUseCompatPadding="true"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:selectableItemBackground" 
    android:padding="10dp"> 

    <TextView 
     android:id="@+id/txt_email" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:textSize="16sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/txt_phone" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/txt_email" 
     android:textColor="@android:color/black" 
     android:textSize="12sp" /> 
</RelativeLayout> 

@Override 
public int getItemViewType(int position) { 
    if (contacts.get(position) == null) 
     return VIEW_TYPE_LOADING; 
    else if (position % 5 == 0) 
     return AD_VIEW; 
    else { 
     return VIEW_TYPE_ITEM; 
    } 
} 

@Override 
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view = null; 
    if (viewType == AD_VIEW) { 
     View adView = LayoutInflater.from(parent.getContext()).inflate(R.layout.add, parent, false); 
     return new AdView(adView); 
    } else if (viewType == VIEW_TYPE_ITEM) { 
     view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_view_row, parent, false); 
     return new UserViewHolder(view); 
    } else if (viewType == VIEW_TYPE_LOADING) { 
     view = LayoutInflater.from(activity).inflate(R.layout.item_loading, parent, false); 
     return new LoadingViewHolder(view); 
    } 
    return null; 
} 

@Override 
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 
    if (holder instanceof AdView) { 
     AdView adView = (AdView) holder; 
     adView.textView.setText("Ads"); 
    } else if (holder instanceof UserViewHolder) { 
     Contact contact = contacts.get(position); 
     UserViewHolder userViewHolder = (UserViewHolder) holder; 
     userViewHolder.phone.setText(contact.getEmail()); 
     userViewHolder.email.setText(contact.getPhone()); 
    } else if (holder instanceof LoadingViewHolder) { 
     LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder; 
     loadingViewHolder.progressBar.setIndeterminate(true); 
    } 
} 

@Override 
public int getItemCount() { 
    return contacts == null ? 0 : contacts.size(); 
} 

XML主

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

XML loadingviewの

のxml: -

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<ProgressBar 
    android:id="@+id/progressBar1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" /> 

+0

それは指定されたインデックスでrecyclerviewの項目と重複する追加したとき(プログレスバー、recyclerview)あなたは目的のために使用しているXMLを投稿してください –

+0

XML – Raghav

+0

のが必要なのはなぜ私の問題は、「AD_VIEW」という名前だけで、余分なビュー..です.. – Raghav

答えて

0

あなたのXMLは、私たちは要素が注文し、お互いに依存しているかを理解させるために必要とされています。 しかし、投稿するまでは、recyclerViewをRelativeLayoutに配置し、重複するビューの下(または上)に設定することができます。 しかし、両方のビュー(リサイクラとオーバーラップしたvjewまたはリサイクラのレイアウトとオーバーラップしたビュー)は、それらが位置依存性を持つように、同じRelativeLayoutの下にある必要があることに注意してください。

+0

私の編集したコードを確認する – Raghav

関連する問題