ビューを拡張し、フレスコ機能を備えたカスタマイズ ビューを作成したい。画像のダウンロードはできますが、表示はできません。私を助けてください、コードは以下の通りです:
public class QView<DH extends DraweeHierarchy> extends View {
private DraweeHolder<DH> mDraweeHolder;
private boolean mInitialised = false;
public QView(Context context) {
super(context);
init(context);
}
@SuppressWarnings("unchecked")
private void init(Context context) {
if(!mInitialised){
GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()).build();
mDraweeHolder = (DraweeHolder<DH>) DraweeHolder.create(hierarchy, context);
mInitialised = true;
}
}
@Override
public void onStartTemporaryDetach() {
super.onStartTemporaryDetach();
mDraweeHolder.onDetach();
}
@Override
public void onFinishTemporaryDetach() {
super.onFinishTemporaryDetach();
mDraweeHolder.onAttach();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mDraweeHolder.onAttach();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mDraweeHolder.onDetach();
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
return mDraweeHolder.onTouchEvent(event) || super.onTouchEvent(event);
}
@Override
protected boolean verifyDrawable(Drawable who) {
if (who == mDraweeHolder.getTopLevelDrawable()) {
return true;
}
return true;
}
public void setImageURI(Uri uri) {
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setOldController(mDraweeHolder.getController())
.build();
mDraweeHolder.setController(controller);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Drawable drawable = mDraweeHolder.getHierarchy().getTopLevelDrawable();
//Drawable drawable = getResources().getDrawable(R.drawable.weekend_move_access);
drawable.setBounds(0, 0, 400, 400);
drawable.draw(canvas);
}
}
MainActivity.java:
LinearLayout ll = (LinearLayout)findViewById(R.id.viewObj);
//SimpleDraweeView view = new SimpleDraweeView(this);
QView view = new QView(this);
LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(400, 400);
view.setLayoutParams(layout);
view.setImageURI(Uri.parse("http://d.hiphotos.baidu.com/image/pic/item/aa64034f78f0f7363465230c0855b319ebc41327.jpg"));
ll.addView(view);