最近我花了一个多小时弄清楚我的xml有什么问题......直到我意识到在android xml中有两个不同的小部件:“view”和“View”。两者都是正确的,并不相同,因为大写的视图给我错误的classcastexception,直到我把它改为小写...我们什么时候使用这些?在android xml中小写和大写“视图”有什么区别?
编辑: 所以,为了创建Android的XML现有部件的修改版本,我不得不使用小写的 “视图”:
<view
android:id="@+id/mybutton1"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="75"
class="com.example.customui2.MainActivity$ArticleFragment$MyButton"
android:contentDescription="@string/logo_desc"
android:src="@drawable/menu_button" />
附加到Widget类:
public static class MyButton extends ImageView
{
public MyButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
};
当使用大写视图时,我在这样的行中有例外:
MyButton button1 = (MyButton) rootView.findViewById(R.id.mybutton1);
,但我也发现实例时大写的观点是在“间隔部件”使用,如:
<View
android:layout_weight="20"
android:layout_width="match_parent"
android:layout_height="0dp"/>
很难回答,如果你没有发布你的xml –
当使用' '时,你有'ClassCastException'?这有点奇怪,你应该使用大写字母。 –
抱歉不要在第一时间发布代码。我认为这是一个相当明显的问题,不值得张贴代码,但现在它在那里! – Savail