我已将 View 扩展为 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>
然后我想像这样在主要 Activity 中使用它:
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,我认为这是最引人注目的条目。
请帮忙!
最佳答案
您没有在 Activity onCreate 中调用 setContentView
关于android - 膨胀自定义 View android问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5303582/