2016-04-11 55 views
0

我想將imageview放在android studio的scrollview中,但它不會讓我在scrollview中拖放imageview。不能把imageview在滾動視圖android studio

這裏是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ccc" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:paddingTop="30dp"> 

    <LinearLayout 
     android:id="@+id/content" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:background="#ffffff" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:textColor="#ffffff"> 

     <TextView 
      android:id="@+id/homepagetxt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:textColor="#000000" 
      android:textStyle="italic" /> 

    </LinearLayout> 


</ScrollView> 

我可以把它放在線性佈局,但它打亂了我的屏幕布局。 但是,我不能像在linearlayout結束標記之後那樣將它放在滾動視圖中。

將imageview放在scrollview中是否有任何限制?

我很感激你的迴應。

回答

1

ScrollView只能有一個直接孩子。如果您想在其中放置多個視圖,則必須將這些視圖放在LinearLayout或RelativeLayout中。

Scrollview can host only one direct child

+0

哦..我可以有一個線性佈局,包含另一個線性佈局和滾動視圖嗎? –

+0

是的,因爲線性(或相對)佈局可以包含多個直接子對象,但滾動視圖只能有一個直接子對象。 –

+0

非常感謝你,幫了我很多。 –

1

將imageview放在scrollview中有什麼限制嗎?

不,但是,ScrollView只能有一個孩子。目前,這是你的LinearLayout