ImageView
中的{p> CardView
未从LRUCache
加载。我确定有些不对劲,但经过几天的调试后无法弄明白。如果只有代码可以在这里完整呈现,但这里是最相关的片段。
TextViews
'RecyclerView
中的 CardView
完全绑定,但不是同一ImageView
中的CardView
s。我确定图像存在于缓存中,因为长按(空白)ImageView
会根据程序在另一个WebView
中显示图像。 <{1}} Fragment1
和AsyncTask
1和2 Fragment
之后加载的静态加载完成。
AsyncTask
布局
CardView
<FrameLayout
android:id="@+id/flDContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rlDetFront"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/cvDet"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="12dp"
card_view:contentPadding="2dp">
<TextView
android:id="@+id/tvDsDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="16sp"/>
<TextView
android:id="@+id/tvDsDistanceUnit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"/>
<RelativeLayout
android:id="@+id/rlMediaLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/headerLayout">
<ImageView
android:id="@+id/DetMedia"
android:layout_width="310dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:adjustViewBounds="true"
android:maxHeight="200dp"
android:maxWidth="310dp"
android:src="@drawable/cake_12"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
:
:
:
:
适配器
ViewPager
class MyShopperPagerAdapter extends FragmentStatePagerAdapter
{
public MyShopperPagerAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int arg)
{
if (arg == 0)
{
fragment = new Fragment1();
}
if (arg == 1)
{
fragment = new Fragment2();
}
if (arg == 2)
{
fragment = new Fragment3();
}
return fragment;
}
@Override
public int getCount()
{
return 3;
}
@Override
public CharSequence getPageTitle(int position)
{
String pageTitle = "";
switch (position)
{
case 0:
pageTitle = "TAB 1";
break;
case 1:
pageTitle = "TAB 2";
break;
case 2:
pageTitle = "TAB 3";
break;
default:
break;
}
return pageTitle;
}
@Override
public int getItemPosition(Object object)
{
return POSITION_NONE;
}
} // of class MyShopperPagerAdapter
适配器的RecyclerView
onBindViewHolder
@Override
public void onBindViewHolder(MyCardHolder myCardHolder, final int position)
{
MyView my = this.mysView.get(position);
String logoFilename = my.getMyerLogo();
String address = my.getAddress();
String city = my.getCity();
String state = my.getState();
String country = my.getCountry();
String zip = my.getZip();
:
:
:
myCardHolder.shopSL.setText(my.getSubLocality());
myCardHolder.myEndDate.setText(UIHelper.makeDisplayDate(Long.parseLong(myEnds), false));
:
:
:
Bitmap tempBitmap;
tempBitmap = fragment1.logoMemCache.get(logoFilename);
myCardHolder.shopLogo.setImageBitmap(tempBitmap);
tempBitmap = fragment1.myetMemCache.get(myFilename);
myCardHolder.myet.setImageBitmap(tempBitmap);
myCardHolder.tvAddress.setText(fullAddress);
myCardHolder.tvPhones.setText(phones);
:
:
:
}
ViewHolder
public class MyCardHolder extends RecyclerView.ViewHolder
{
private final String LOG_TAG = "POJO MyCardHolder";
RelativeLayout llMyCardFront;
RelativeLayout myTakenCounterLayout;
RelativeLayout myDateLayout;
TextView tvDistance;
TextView tvAddress;
TextView tvPhones;
TextView distanceUnit;
ImageView det;
TextView myTop;
TextView myBot;
ImageView shopLogo;
TextView shopName;
:
:
:
// FAB toolbar
FloatingActionButton fabDirections, fabCallMobile, fabCallLandline, fabWebsite;
public MyCardHolder(View myItemView)
{
super(myItemView);
RelativeLayout myUserStatusLayout;
llMyCardFront = (RelativeLayout) myItemView.findViewById(R.id.rlMyetFront);
tvDistance = (TextView) myItemView.findViewById(R.id.tvMysDistance);
claimButton = (Button) myItemView.findViewById(R.id.btMyClaim);
distanceUnit = (TextView) myItemView.findViewById(R.id.tvMysDistanceUnit);
det = (ImageView) myItemView.findViewById(R.id.DetMedia);
myTop = (TextView) myItemView.findViewById(R.id.primaryTitle);
myBot = (TextView) myItemView.findViewById(R.id.subTitle);
shopLogo = (ImageView) myItemView.findViewById(R.id.shopLogo);
shopName = (TextView) myItemView.findViewById(R.id.shopName);
:
:
:
:
fabDirections = (FloatingActionButton) myItemView.findViewById(R.id.fabDirections);
:
:
:
}
}
class MyTapListener implements View.OnClickListener
{
final String LOG_TAG = "MyTapListener";
@Override
public void onClick(View myItemView)
{
CardView cardFront = (CardView) myItemView.findViewById(R.id.cvMyet);
CardView cardBack = (CardView) myItemView.findViewById(R.id.cvMyetBack);
RelativeLayout llMyetBack = (RelativeLayout) myItemView.findViewById(R.id.rlMyetBack);
RelativeLayout llMyetFront = (RelativeLayout) myItemView.findViewById(R.id.rlMyetFront);
/* Some layout animations here when the user clicks on a CardView */
:
:
:
}
}
class FABToolbarListener implements View.OnClickListener
{
/* FAB listener */
:
:
:
} // of class FABToolbarListener
class MyMediaListener implements View.OnLongClickListener
{
@Override
public boolean onLongClick(View clickedPic)
{
int id = clickedPic.getId();
Context context = clickedPic.getContext();
String filename = (String) clickedPic.getTag(id);
String shopName = (String) clickedPic.getTag(R.id.action_show_website);
showOriginalImage(context, picFilename, shopName);
return false;
}
private void showOriginalImage(Context context, String filename, String shopName)
{
Intent fullMyetIntent = new Intent(context, ZoomerActivity.class);
fullDIntent.putExtra(MyContract.D_PREFIX, filename);
fullDIntent.putExtra(MyContract.D_PICKED, shopName);
context.startActivity(fullDIntent);
} // of showOriginalImage() }
输出
我在这里缺少任何CardView
- CardView
- ImageView
关系或怪癖或专家技巧吗?
请告诉我您需要检查的其他代码。
非常感谢!