我创建了一个带有一些视图组件的片段。我需要只刷一下该组件的图像,但我的代码完整片段正在交换。我怎样才能只拍摄碎片的图像 贝娄是我的代码。我使用ViewPager来做滑动片段
public class DetailedSwiperImageAdapter extends PagerAdapter {
private Context mContext;
FoodDetail foodDetails;
private List<FoodDetail> foodDetailsList = new ArrayList<>();
private final int currentPosition;
public DetailedSwiperImageAdapter(Context fragmentContext, List<FoodDetail> foodDetail, int position) {
mContext = fragmentContext;
foodDetailsList = foodDetail;
currentPosition = position;
}
@Override
public int getCount() {
return foodDetailsList.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.detailed_fragment, container,
false);
foodDetails = foodDetailsList.get(position);
View view = populateDataForDetailedLayout(viewLayout, foodDetails);
container.addView(view);
return view;
}
/*
* fetch the data from the timeline and display it in the detailed screen
*/
private View populateDataForDetailedLayout(View viewLayout, FoodDetail foodDetails) {
((TextView) viewLayout.findViewById(R.id.detailed_meal_type)).setText(foodDetails.getFoodType().name());
ImageView dishImageView = (ImageView) viewLayout.findViewById(R.id.dish_image_view);
File imgFile = new File(foodDetails.getFoodImageLocalPath());
if (imgFile.exists()) {
dishImageView.setImageURI(Uri.fromFile(imgFile));
}
final TextView detaileMessage = (TextView) viewLayout.findViewById(R.id.detaile_message);
TextView detaileLocation = (TextView) viewLayout.findViewById(R.id.detaile_location);
TextView detaileDishName = (TextView) viewLayout.findViewById(R.id.detaile_dish_name);
TextView detaileTime = (TextView) viewLayout.findViewById(R.id.detaile_time);
ImageView emojiImage = (ImageView) viewLayout.findViewById(R.id.emoji_detailed);
detaileDishName.setText(foodDetails.getFoodName());
String smrtMsg = foodDetails.getSmartmessage();
if (smrtMsg != null) {
smrtMsg = smrtMsg.replaceAll("[\n\r]", "");
detaileMessage.setText(smrtMsg);
}
if (foodDetails.getIntentEmojiUnicode() != null) {
Picasso.with(mContext).load(RemoteUtils.getIntentImageURIString(foodDetails.getIntentEmojiUnicode(), null, "khanapal")).into(emojiImage);
}
CharSequence time = DateUtils.getRelativeDateTimeString(mContext,
foodDetails.getStartTime().getTime(), DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
detaileTime.setText(time);
String location = "";
if (!TextUtils.isEmpty(foodDetails.getStreet())) {
location = foodDetails.getStreet();
} else if (!TextUtils.isEmpty(foodDetails.getLocationName())) {
location = foodDetails.getLocationName();
} else if (!TextUtils.isEmpty(foodDetails.getCity())) {
location = foodDetails.getCity();
} else if (!TextUtils.isEmpty(foodDetails.getCountry())) {
location = foodDetails.getCountry();
}
location += " - " + foodDetails.getLocationUnformattedAddress() + "";
if (foodDetails.getLocationUnformattedAddress() == null) location = "No location";
detaileLocation.setText(location);
//used for message edting on click of smart message text editor
detaileMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = detaileMessage.getText().toString();
editMessage(message, detaileMessage);
}
});
return viewLayout;
}
}
答案 0 :(得分:0)
尝试为您的图片创建ViewDragHelper。
https://developer.android.com/reference/android/support/v4/widget/ViewDragHelper.html