2014-02-05 21 views
0

所以,最近我一直在試圖爲我的應用做一個佈局。我基本上需要一個TextView,一個ImageView,一個ListView和一個多行TextView。所以,ListView的所有內容都是完全可見的。在屏幕的底部有ListView,有1.5個元素可見,並且列表本身可以滾動。但是,在它下面沒有那個TextView的蹤跡,並且只有ListView的一小部分可見的事實令人討厭。但是,我的ListView應該包含最多6-8個元素,那麼是否有任何簡單的技巧將ScrollView作爲所有這些的父項,並使其下方的ListView和TextView完全可見?就像修改ListView的大小一樣,所以它不必滾動並導致進入ScrollView時出現這個問題,我已經讀了大約一千次?提前致謝!希望有人會幫助因爲我迫切需要這個。我是Android開發人員的初學者,但迄今爲止表現很好。再次感謝。ListView prob - Android

編輯:所以,這裏是我做過什麼:

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

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

     <TextView 
      android:id="@+id/tvTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="20dp" 
      android:text="Large Text" 
      android:textSize="25sp" /> 

     <ImageView 
      android:id="@+id/ivPicture" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="18dp" 
      android:src="@drawable/android" /> 

     <ListView 
      android:id="@+id/lvElements" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="23dp" > 
     </ListView> 

     <TextView 
      android:id="@+id/tvDesc" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" > 
     </TextView> 
    </LinearLayout> 

</ScrollView> 

但儘管如此,ListView控件現在還不是滾動的,它表明只有第一個元素。但是,我可以看到最後一個TextView。現在怎麼辦?

+0

我不知道O_O我刪除我的答案,以便其他人將試圖爲您解決這個例子。 – Piovezan

+1

從不在ListView中放入ListView,請參閱http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing – 2Dee

回答

0

刪除ScrollView這是示例代碼嘗試這種

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

    <TextView 
     android:id="@+id/tvTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="20dp" 
     android:text="Large Text" 
     android:textSize="25sp" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

    <ListView 
     android:id="@+id/lvElements" 
     android:layout_width="wrap_content" 
     android:layout_height="67dp" 
     android:layout_marginTop="23dp" 
     android:layout_weight="0.79" > 
    </ListView> 

    <TextView 
     android:id="@+id/tvDesc" 
     android:layout_width="fill_parent" 
     android:layout_height="14dp" 
     android:layout_marginTop="20dp" 
     android:layout_weight="0.06" 
     android:text="Last text" > 

    </TextView> 

</LinearLayout> 

您可以編輯android:layout_height="67dp"ListView此代碼。

0

在ScrollView中嵌套一個ListView是一個壞主意。相反,您可以將ListView上方的視圖添加爲頁眉,並將其作爲頁腳添加到下面:將視圖放置在頁眉的新佈局中,併爲頁腳分別放置一個視圖。那麼你可以做listview.addHeaderView(headerView)listview.addFooterView(footerView)。這將使您的整個ListView平滑滾動。

退房就如何增加他們Android listview with header and footer buttons