2011-10-17 39 views
9

Tôi nhận được lỗi này:Android Lỗi Phân tích XML XML: rác sau khi tài liệu yếu tố

Nhiều chú thích tìm thấy tại dòng này: - Các đánh dấu trong tài liệu sau phần tử gốc phải nổi hình thành. - lỗi: Lỗi phân tích cú pháp XML: rác sau phần tử tài liệu

Điều này xuất hiện trên TextView thứ hai trong tệp xml này.

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/text1" 
      android:textSize="16sp" 
      android:textStyle="bold" 
      android:textColor="#FFFF00" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"></TextView> 

<TextView android:id="@+id/text2" 
    android:textSize="12sp" 
    android:textStyle="bold" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    ></TextView> 

<TextView android:id="@+id/text3" 
    android:typeface="sans" 
    android:textSize="14sp" 
    android:textStyle="italic" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></TextView> 

Bất kỳ ý tưởng nào về sai lầm tôi đang thực hiện? Tất cả trợ giúp đều được đánh giá cao.

Trả lời

25

Tài liệu XML chỉ có thể có 1 phần tử gốc. Bạn có 3 yếu tố như vậy. Bạn nên gửi kèm theo các yếu tố TextView của mình bên trong một bố cục, chẳng hạn như một LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <!-- TextView elements here --> 

</LinearLayout> 

Hủy bỏ thuộc tính xmlns trên các yếu tố TextView đầu tiên.

+2

Cảm ơn bạn, tôi sẽ chấp nhận câu trả lời của bạn! – Lijap

0

bạn nên encapsule các yếu tố của bạn trong bố trí, chẳng hạn như LinearLayout. Bạn có thể xem tệp cấu hình bố cục trong sự tồn tại.

Các vấn đề liên quan