【发布时间】:2011-11-18 15:43:31
【问题描述】:
我的课程 CalloutView 是从 RelativeLayout 扩展而来的。目前没有任何方法,只是重新定义了构造函数。
我也有一个 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<com.example.CalloutView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="70dp">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
android:background="@drawable/button_disclose"
android:src="@drawable/disclose" />
</com.example.CalloutView>
我通过此代码扩展 CalloutView 实例的布局:
this.calloutView = (CalloutView) ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.callout_view, null);
this.calloutView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 105));
this.calloutView.measure(MeasureSpec.makeMeasureSpec(400, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(105, MeasureSpec.EXACTLY));
完美呈现。 ImageButton 应该出现在它的右侧。
但是当我给CalloutView添加背景时:
<com.example.CalloutView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="@drawable/callout">
...
</com.example.CalloutView>
它只呈现背景,但ImageButton 不会出现。
编辑
我使用 NinePatch 图像作为背景。如果我用非 NinePatch 替换它,一切正常。 Android 中的错误?
主要问题是,如果设置了背景,为什么不渲染 ImageButton?
【问题讨论】:
标签: android background android-relativelayout imagebutton xml-layout