Android 让Eclipse在图形xml视图上显示自定义组件
我只是扩展了ImageView,这样图像就可以全宽显示了。像这样:Android 让Eclipse在图形xml视图上显示自定义组件,android,xml,eclipse,eclipse-adt,Android,Xml,Eclipse,Eclipse Adt,我只是扩展了ImageView,这样图像就可以全宽显示了。像这样: public class BannerImageView extends ImageView { public BannerImageView(Context context) { super(context); } public BannerImageView(Context context, AttributeSet attrs) { super(context,
public class BannerImageView extends ImageView {
public BannerImageView(Context context) {
super(context);
}
public BannerImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BannerImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth();
setMeasuredDimension(width, height);
}
}
在XML中,我声明如下:
<com.whatever.next.BannerImageView
android:id="@+id/banner"
android:src="@+drawable/logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
我收到以下错误:
main.xml:无法解析drawable com.android.layoutlib.bridge。ResourceValue@48537a0f在属性src中
然后我得到了预期的空指针异常
正如我所想,我很困惑,因为我没有改变ImageView在图形布局中显示的默认行为。我已经通读了其他类似的问题,这让我更加困惑
为了便于记录,上述代码在实际设备上运行良好
感谢您的帮助 而不是
android:src="@+drawable/logo"
使用
否+对于src属性我有另一个更复杂的自定义组件。它基本上是在画布上画一个时钟,然后为一只旋转的秒针设置动画。我需要使用View.isInEditMode吗?Eclipse建议这样做,但当使用它实现时,我只会得到更多无法通过堆栈跟踪的错误。您能把这作为单独的问题和更多的细节吗?为什么要覆盖isInEditMode?我只是按照Eclipse的建议提一下。我会按你说的分别发帖。
android:src="@drawable/logo"