显示占位符在recyclerview
我想显示的最初加载从API获取数据之前的骨架图一RecyclerView的图像。在下面的示例中,正在显示一个简单的图像视图和文本。显示占位符在recyclerview
<android.support.v7.widget.CardView
android:id="@+id/cv_store_offer_display"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="50dp"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Foo FOO"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
我想知道如何在加载图像/文本之前让我的Recyclerview显示视图。我正在使用毕加索加载图像。用于显示RecyclerView内容的mikepenz FastAdapter。
我还试图用一个进度条为https://*.com/a/12342168/371557提及。但即使可见性设置为可见,进度条也不会显示。
,你可以使用类似
picasso.load(url)
.placeholder(R.drawable.place_holder)
.into(imageView);
感谢您的回答约翰。是否有可能将动画对象设置为占位符? –
是的,你可以绘制的是像'' –
一些奇怪的原因,我的recyclerview是怪怪的。它实际上从不加载占位符图像。它在占位符和URL之间的图像之间切换,只是在分秒之差。直到那时UI才显示没有RecyclerView的标志 –
<!--You Would Apply Like this-->
Picasso.load(url)
.placeholder(R.drawable.img_place_holder)
.into(imageView);
<!--Use ProgressBar-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/sliding_popup_window"
android:layout_below="@+id/bank_info_toolbar"
>
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
//Your ProgressBar code
class Synch extends AsynchTask<void, void, void> {
public void onPreExecute() {
//your code
progressBar.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
}
public void doinBackground() {
//Your Code
}
public void onPostExecute() {
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
你能不能只指定在XML的形象呢? '机器人:SRC =“@绘制/占位符”' – StuStirling
你能证明你的代码中设置图像毕加索.. –
设置'''机器人:SRC =“@绘制/占位符”'''使它看起来静态..因此,我想显示一个进度条:)任何其他想法? –