2013-12-18 29 views
0

我有一個屏幕和許多佈局項目。我想在ScrollView下除了頁腳按鈕以外的整個屏幕,以便在小屏幕中,如果大小減小,它將向下滾動。但是,當我添加ScrollView作爲父佈局的所有它崩潰說「滾動視圖不能處理太多的子項」或它會搞亂佈局。任何解決方案下面是我的代碼和屏幕截圖如何在滾動視圖下添加除屏幕按鈕之外的整個屏幕

請注意在下面的代碼中,我不是把所有東西放在ScrollView下,但我希望一切都進入ScrollView除了頁腳按鈕。

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/windowtitle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:background="#0a2436" 
      android:gravity="center_horizontal|center_vertical" 
      android:paddingBottom="10dip" 
      android:paddingTop="10dip" 
      android:src="@drawable/logo" > 
     </ImageView> 

     <ScrollView 
     android:id="@+id/formTab" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 

     <ListView 
      android:id="@+id/listview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="#ffffff" 
      android:divider="@android:color/darker_gray" 
      android:dividerHeight="1dip" 
      android:drawSelectorOnTop="false" 
      android:focusable="false" 
      android:paddingTop="0dip" 
      android:scrollbars="none" /> 

     </ScrollView> 

     <!-- android:divider="@color/listDivider" --> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#e7ebee" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/list" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.5" 
       android:gravity="center_vertical" 
       android:paddingTop="10dip" 
       android:paddingBottom="7dip" 
       android:paddingLeft="10dip" 
       android:text="SNS Connection" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="#737577" 
       android:textSize="20sp" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ffffff" 
       android:paddingTop="5dip" 
       android:gravity="center_vertical" 
       android:orientation="horizontal" > 

       <ImageView 
        android:id="@+id/facebook" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:paddingLeft="10dip" 
        android:src="@drawable/facebook" /> 

       <TextView 
        android:id="@+id/list" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:gravity="center_vertical" 

        android:paddingLeft="10dip" 
        android:text="Facebook" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#444444" 
        android:textSize="20sp" /> 

       <ImageView 
        android:id="@+id/facebook" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right|center_vertical" 
        android:paddingRight="15dip" 
        android:src="@drawable/ok" /> 
      </LinearLayout> 

      <TextView android:id="@+id/tokentextfacebook" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/facebook" 
        android:textSize="14sp" 
        android:paddingLeft="10dip" 
        android:paddingBottom="5dip" 
        android:background="#ffffff" 
        android:text="Your token is run out. Please reconnect" 
        android:textColor="#444444" 
        android:gravity="left" 
       /> 

      <View 
       android:layout_width="fill_parent" 
       android:layout_height="1dp" 
       android:background="@android:color/darker_gray"/> 

      <LinearLayout 
       android:id="@+id/linearLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ffffff" 
       android:paddingTop="5dip" 
       android:gravity="center_vertical" 
       android:orientation="horizontal" > 

       <ImageView 
        android:id="@+id/twitter" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:paddingLeft="10dip" 
        android:src="@drawable/twitter" /> 

       <TextView 
        android:id="@+id/list" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:gravity="center_vertical" 
        android:paddingLeft="10dip" 
        android:text="Twitter" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#4a82ae" 
        android:textSize="20sp" /> 

       <ImageView 
        android:id="@+id/twitter" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right|center_vertical" 
        android:paddingRight="15dip" 
        android:src="@drawable/ok" /> 
      </LinearLayout> 

      <TextView android:id="@+id/tokentexttwitter" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/facebook" 
        android:textSize="14sp" 
        android:paddingLeft="10dip" 
        android:paddingBottom="5dip" 
        android:background="#ffffff" 
        android:text="Your token is run out. Please reconnect" 
        android:textColor="#444444" 
        android:gravity="left" 
       /> 

     </LinearLayout> 
    </LinearLayout> 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerInParent="true" 
     android:gravity="bottom" 
     android:stretchColumns="*" > 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" > 

      <Button 
       android:id="@+id/btnManualLookup" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:background="#092435" 
       android:gravity="center" 
       android:padding="15dip" 
       android:text="Activity" 
       android:textColor="#ffffff" /> 

      <Button 
       android:id="@+id/supportbutton" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:background="#092435" 
       android:gravity="center" 
       android:padding="15dip" 
       android:text="Support" 
       android:textColor="#ffffff" /> 

      <Button 
       android:id="@+id/messagebutton" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:background="#092435" 
       android:gravity="center" 
       android:padding="15dip" 
       android:text="Messages" 
       android:textColor="#ffffff" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
+1

List-view有自己的Scroller函數,所以爲什麼你需要在ScrollView中添加。 –

+0

在使用列表視圖時,不需要使用滾動視圖。刪除它並檢查 – AndroidHacker

+0

原因是當我在較小的屏幕上嘗試相同的佈局時,它會在部分下方放鬆出來,所以想着如果我們可以在滾動視圖下得到相同的佈局。此外listview是靜態的,只有4個項目 – user45678

回答

0

你不應該把ListView一個ScrollView內,因爲ListView類實現了自己的滾動,它只是因爲他們都受同一母公司ScrollView處理不接收手勢。我強烈建議你以某種方式簡化你的佈局。例如,您可以將要滾動的視圖添加爲ListView作爲頁眉或頁腳。

如果您只想爲頁腳添加滾動視圖,則只能將頁腳添加爲您的ListView中的視圖,這樣才能提供平滑滾動。

0

你可以做一些這樣的事情。確保滾動視圖只包含一個孩子..檢查我的代碼並分析它。希望聽起來不錯。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 

     > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:src="@drawable/ic_launcher" 
       /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="center text" 
       android:layout_gravity="center" 
       /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:src="@drawable/ic_launcher" 
       /> 

     </LinearLayout> 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:layout_marginBottom="2dp" 
     android:background="@color/black" > 
    </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:src="@drawable/ic_launcher" 
       /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="center text" 
       android:layout_gravity="center" 
       /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:src="@drawable/ic_launcher" 
       /> 

     </LinearLayout> 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:layout_marginBottom="2dp" 
     android:background="@color/black" > 
    </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:src="@drawable/ic_launcher" 
       /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="center text" 
       android:layout_gravity="center" 
       /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:src="@drawable/ic_launcher" 
       /> 

     </LinearLayout> 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:layout_marginBottom="2dp" 
     android:background="@color/black" > 
    </LinearLayout> 

     </LinearLayout> 

    </ScrollView> 


</LinearLayout>