【发布时间】:2011-03-14 19:42:39
【问题描述】:
我已将视图扩展到 ScrollImageView。然后我把它放到xml中:
在 main.xml 中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/my_xml" />
<com.Android.Maps03.ScrollImageView
android:id="@+id/BaseView" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
然后我想在这样的主要活动中使用它:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ScrollImageView sIV = (ScrollImageView)findViewById(R.id.BaseView);
Bitmap markerImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.mapbase );
sIV.setImage(markerImage);
当我运行应用程序时,不会出现 ScrollImage。
类(ScrollImageView)的构造函数是这样的:
public ScrollImageView(Context context, AttributeSet attributeSet) {
super(context);
initScrollImageView(context);
private void initScrollImageView(Context context) {
mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mPadding = DEFAULT_PADDING;
}
你有什么想法吗?
谢谢。
评论 #1 是的,我忘记了,但我有同样的问题。
评论 #2 不,我用第二个 /> 关闭所有布局,而不是关闭两次
评论 #3 这是新的 logcat,我认为这是最了不起的条目。
请帮忙!
【问题讨论】:
-
不确定这是否是问题,但超级调用应该是 super(context, attributeSet)。 attributeSet 包含 xml 中的所有属性。
-
您还要关闭 ScrollImageView 元素两次。
-
@Gonzalo Diaz Harcha 你确定设置的当前布局定义的是包含滚动图像视图的布局吗?...如果它在对象链的某个地方出现问题,它可能会在你面前抛出试图找到它,听起来更像是您正在查找的视图不包含嵌套视图,并且显然将 null 转换为类型从来都不是一件有趣的事情。所以你的活动视图使用
setContentView()传递包含视图? -
我在问题中添加了更多代码。 @Quintin Robinson 我不知道layot 是否包含滚动图像视图。错误日志说这个“com.Android.Maps03.ScrollImageView 无法实例化”。我认为这可能是问题所在。集合是 setContentView(R.layout.main);程序给出的main.xml。
-
@Gonzalo Diaz Harcha 好的两件事,你已经扩展了抛出错误的行,哪一行实际上抛出了异常?另外,如果您在调试中运行应用程序,您是否可以进入
ScrollImageView构造函数并查看它是否在特定行出现异常?