【发布时间】:2014-07-08 22:12:31
【问题描述】:
在闲置的 xml 中,我将 LinearLayout 设置为 @+id/camera,但是当我调用 (LinearLayout) findViewById(R.id.camera) 时,我得到了 ClassCastException: Button can not be cast to Linearlayout。换句话说,id 是如何应用于其中一个按钮的。如果我删除第二个android:layout_above="@+id/camera",那么它工作正常。这是怎么回事?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true" />
<View
android:id="@+id/center"
android:layout_height="match_parent"
android:layout_width="0dp"
android:visibility="invisible"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/front"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="front"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/center"
android:layout_above="@+id/camera" />
<Button
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="back"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/center"
android:layout_above="@+id/camera" />
<Button
android:id="@+id/export"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="export"
android:layout_alignParentBottom="true"
android:layout_below="@+id/camera" />
</RelativeLayout>
【问题讨论】:
-
再次确认您没有意外导入
android.R。
标签: android xml android-relativelayout