XML布局中奇怪的混合

时间:2014-07-19 22:08:38

标签: android xml android-layout

我有一个奇怪的情况,其中android构建似乎正在读取一个元素的id属于另一个元素。

以下是相关的XML:

    <TextView 
        android:layout_marginTop="30dp"
        android:id="@+id/tour_explanation"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        style="@android:style/TextAppearance.DeviceDefault.Large"/>
    <LinearLayout
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:id="@+id/audio_container"
            android:orientation="horizontal">
        </LinearLayout>

这是代码中产生错误的行:

((TextView)v.findViewById(R.id.tour_explanation)).setText(b.getString(ToursPagerAdapter.STATION_TEXT));

这就是错误:

java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView

由于某种原因,TextView中的id与LinearLayout相关联。我尝试使用带有和没有结束标记的LinearLayout - 没有区别。如果我颠倒顺序并在LinearLayout之后放置TextView,则错误消失。

是什么原因引起的?我怎么能让它消失?

0 个答案:

没有答案