我有一个自定义视图(它扩展了GLSurfaceView)我试图在我的应用程序中使用。使用它的xml布局似乎正在正确加载(我为视图设置的属性被应用),但是该视图的构造函数和onFinishInflate方法都不会被调用。我还应该补充说,我对android平台很陌生,所以这可能是一个愚蠢的错误。构造函数和onFinishInflate都不需要自定义视图
这里是我的main.xml
<?xml version="1.0" encoding="utf-8"?>
#<!-- Status Bar -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@drawable/status_bkg">
#<!-- Location label -->
<TextView
android:text="Location"
android:textColor="#FFFFFF"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
#<!-- Date/Time label -->
<TextView
android:text="Date and Time"
android:textColor="#FFFFFF"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" />
</LinearLayout>
#<!-- ChartView -->
<View class="com.xxx.yyy.ChartView" android:id="@+id/chartView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1">
</View>
的ChartView是自定义GLSurfaceView。此布局已加载,并且ChartView具有指定的绿色背景。但是,我的设置(代码)没有发生。我试过把它放在两个构造函数和onFinishInflate方法中,但它们莫名其妙地没有被调用。我验证过的类名是正确的(在xxx.yyy只是为了隐藏公司在这个岗位。
我也尝试了不同形式的XML参考
<com.xxx.yyy.ChartView android:id="@+id/chartView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"/>
,但这去世时加载的活动说,构造
ChartView(上下文的背景下,ATTRS的AttributeSet)
不存在(虽然它肯定是在我的代码)。
任何人都有可能发生什么事情的提示?
粘贴视图的Java代码。 – Cristian 2010-12-20 23:18:41