Inflate自定义视图android问题
我已将视图扩展为 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 是的,我忘记了,但我也有同样的问题。
Comment #2 不,我用第二个/>关闭所有布局,而不是关闭两次
Comment #3 这是新的 logcat,我认为这是最引人注目的条目。
请帮忙!
i have extended view into a ScrollImageView. Then i put that into the xml:
In 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>
Then i want to work with that in the main activity like this:
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);
When i run the app, the ScrollImage doesnt Appear.
The constructor of the clase (ScrollImageView) is this:
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;
}
do you have and idea?
Thanks.
Comment #1 Yes, i forget that, but i have the same problem.
Comment #2 No, im closing all the layout with the second />, not closing twice
Comment #3 This is the new logcat, i think this is the most remarkable entries.
Plz Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有在 Activity onCreate 中调用 setContentView
You aren't calling setContentView in your Activity onCreate