2014-04-03 112 views
1

我無法將滾動視圖添加到我的佈局。我該怎麼辦?滾動視圖無用

錯誤說: 在此行找到多個註釋: - 這個滾動型的觀點是無用的(無子女,無背景,無標識,無樣式) - 元素類型「滾動型」必須由相匹配的結束終止-標籤 」」。

<Scrollview xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:orientation="vertical" > 
</LinearLayout> 






<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="کد اطلاعات عمومی گوشی" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button1" 
    android:layout_centerHorizontal="true" 
    android:text="کد فکتوری ریست گوشی بدون از بین بردن اپلیکیشن ها" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button2" 
    android:layout_centerHorizontal="true" 
    android:text="کد فکتوری ریست کلی" /> 

<Button 
    android:id="@+id/button4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button3" 
    android:layout_centerHorizontal="true" 
    android:text="اطلاعات دوربین" /> 

<Button 
    android:id="@+id/button5" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button4" 
    android:layout_centerHorizontal="true" 
    android:text="تغییر عملکرد دکمه power/end call" /> 

<Button 
    android:id="@+id/button6" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button5" 
    android:layout_centerHorizontal="true" 
    android:text="پشتیبان گیری از فایل ها(عکس ها ، یادداشت ها و...)" /> 

<Button 
    android:id="@+id/button7" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button6" 
    android:layout_centerHorizontal="true" 
    android:text="انجام تست و تنظیم بعضی از تنطیمات گوشی" /> 

<Button 
    android:id="@+id/button8" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button7" 
    android:layout_centerHorizontal="true" 
    android:text="کد تست های سخت افزاری" /> 

<Button 
    android:id="@+id/button9" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button8" 
    android:layout_centerHorizontal="true" 
    android:text="Button" /> 

<Button 
    android:id="@+id/button10" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/button9" 
    android:layout_centerHorizontal="true" 
    android:text="Button" /> 

</ScrollView> 
</Scrollview> 
</LinearLayout> 
</LinearLayout> 

請更正代碼。感謝提前

+1

你還應該更好地使用strings.xml來獲取你的文本 – donfuxx

回答

0

新的佈局:

<Scrollview 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" 
    > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:orientation="vertical" 
    > 
     <Button 
      android:id="@+id/button1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:text="?? ??????? ????? ????" 
     /> 
     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button1" 
      android:layout_centerHorizontal="true" 
      android:text="?? ?????? ???? ???? ???? ?? ??? ???? ???????? ??" 
     /> 
     <Button 
      android:id="@+id/button3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button2" 
      android:layout_centerHorizontal="true" 
      android:text="?? ?????? ???? ???" 
     /> 
     <Button 
      android:id="@+id/button4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button3" 
      android:layout_centerHorizontal="true" 
      android:text="??????? ??????" 
     /> 
     <Button 
      android:id="@+id/button5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button4" 
      android:layout_centerHorizontal="true" 
      android:text="????? ?????? ???? power/end call" 
     /> 
     <Button 
      android:id="@+id/button6" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button5" 
      android:layout_centerHorizontal="true" 
      android:text="??????? ???? ?? ???? ??(??? ?? ? ??????? ?? ?...)" 
     /> 
     <Button 
      android:id="@+id/button7" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button6" 
      android:layout_centerHorizontal="true" 
      android:text="????? ??? ? ????? ???? ?? ??????? ????" 
     /> 
     <Button 
      android:id="@+id/button8" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button7" 
      android:layout_centerHorizontal="true" 
      android:text="?? ??? ??? ??? ??????" 
     /> 
     <Button 
      android:id="@+id/button9" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button8" 
      android:layout_centerHorizontal="true" 
      android:text="Button" 
     /> 
     <Button 
      android:id="@+id/button10" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button9" 
      android:layout_centerHorizontal="true" 
      android:text="Button" 
     /> 
    </LinearLayout> 
</Scrollview> 
+0

然後他會遇到錯誤「ScrollView只能有一個孩子」,所以解決方案也應該是刪除第一個LinearLayout上的右括號並添加他們就在ScrollView的右括號之前。 – Guardanis

+1

我編輯了我的答案 –

+0

你會寫出正確的代碼形式嗎? –

1

滾動型只能包含一個孩子,因此你需要有這樣的事情:

<ScrollView> 
    <LinearLayout> 
     <Button /> 
     <Button /> 
     <Button /> 
     <Button /> 
    </LinearLayout> 
</ScrollView> 

也有一堆關閉標籤的在你應該擺脫的末尾:

</Scrollview> 
</LinearLayout> 
</LinearLayout> 
2

ScrollView只能帶一個子視圖。你需要做的是把你的視圖像LinearLayout或RelativeLayout視圖中的所有按鈕,然後添加一個scrollView。