2017-07-27 75 views
0

我有一个应用程序,我想在recyclerview中显示服务器的dataList,当我滚动到recyclerView结束时,想要显示底部的进度条,并且我还在recyclerview之间添加了AdsView,但它与recyclerView的项目重叠指定的索引。显示视图时,它与recyclerview中的项目重叠?

代码: -

@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" /> 

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> 

的XML

XML loadingview的: - 需要为了让我们理解元素是如何排序,并视对方

<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

请发布您用于此目的的XML(Progressbar,recyclerview) –

+0

为什么需要xml – Raghav

+0

我的问题是只有当额外的视图名为“AD_VIEW”时,它与指定索引处的recyclerview项重叠时才被命名为“AD_VIEW”。 .. – Raghav

回答

0

你的XML。 但是,在您发布它之前,您可以将您的recyclerView放置在RelativeLayout中,并将其设置为低于(或高于)其重叠视图。 但是请注意,两个视图(回收站和重叠视图或回收站的布局以及重叠视图)应该位于相同的RelativeLayout下,以便它们可以具有位置依赖性。

+0

请检查我编辑的代码 – Raghav

相关问题