2017-03-03 182 views
1

#我使用了滾動列表視圖裏面,但列表視圖不滾動視圖作爲頂級父視圖爲什麼列表視圖不滾動滾動視圖裏面在nativescrit angular2

component.html 
    <ScrollView> 
    <StackLayout class="zindex"> 
     <!--<AutoComplete [items]="ArrayVillage" (itemTap)="itemTapped($event)"> </AutoComplete>--> 
     <SearchBar row="0" #sb hint="Search for a country and press enter" (clear)="onClear()" [text]="searchPhrase" (submit)="onSubmit(sb.text)"></SearchBar> 
     <ListView row="1" [items]="myItems" class="list-group"> 
      <template let-item="item"> 
      <GridLayout class="item" class="list-group-item"> 
       <Label [text]="item.name" class="list-group-item-heading"></Label> 
      </GridLayout> 
      </template> 
     </ListView> 
     </StackLayout> 
<ScrollView> 
+0

如果是這樣的,除非你想要的搜索欄來移動你不需要滾動視圖的整個佈局。 Listviews默認爲滾動。也許你是在一個不同的最終結果比我想象的,但如果你只是想列表滾動刪除滾動視圖 –

+0

我有很多組件內滾動不僅列表視圖 –

回答

0

內滾動通過包裝滾動型成嘗試它AbsoluteLayout

<AbsoluteLayout> 
    <ScrollView> 
     <StackLayout class="zindex"> 
     //Rest of stuff 
     </StackLayout> 
     <ScrollView> 
</AbsoluteLayout> 
+0

我做了它的第一,但它不工作 –

0

在另一個滾動視圖內不是一個好習慣。這是行不通的scrollview試圖計算無限視圖,並與一個可滾動的內部可以工作只是在某些情況下控制父視圖,但不要去那種痛苦的方式。

在你的代碼中,我有一個問題,你爲什麼要滾動SearchBar?嘗試這種結構,我認爲是你想要的。

<StackLayout> 
<SearchBar></SearchBar> 
<ListView> 
    <template> 
     <GridLayout > 
      <Label ></Label> 
     </GridLayout> 
    </template> 
</ListView> 

The SearchBar is fixed and the List scrolllable

+0

我有給定修復大小的ListView內滾動視圖,但列表視圖不滾動 –

+0

檢查更新的答案,我希望它hests你,否則,發送你想要在視圖中得到,所以我們可以管理一個解決方案來實現它。 –

+0

我有父視圖作爲scrollview裏面,我有很多組件像textview和drpodown列表等,我有listview也不滾動,如果我使用滾動條作爲其父視圖.. –

0

看那video,玩模擬器,你會看到,它似乎工作,但「計算機鼠標滾動」當你使用點擊嘗試beggining滾動它不再工作,並且是因爲屏幕不知道哪個可滾動元素必須滾動。

要做到2個滾動部件可以是一個解決方案,如在視頻的結尾(我在Nativescript實現使用Javascript,因爲我在一個項目工作,但幾乎是相同的)

<StackLayout> 
    <Label fontSize="20" color="blue" text="You can do two scrollable parts" textWrap="true" /> 
    <Button text="to" /> 
    <ListView items="{{ items }}" height="300" loaded="onLoaded" itemLoading="onItemLoading" itemTap="onItemTap"> 
     <ListView.itemTemplate> 
       <Label text="{{ name }}" textWrap="true" /> 
     </ListView.itemTemplate> 
    </ListView> 
<ScrollView> 
    <StackLayout> 
     <Button text="1" /> 
     <Button text="2" /> 
     <Button text="3" /> 
     <Button text="4" /> 
     <Button text="5" /> 
     <Button text="6" /> 
     <Button text="3" /> 
     <Button text="4" /> 
     <Button text="5" /> 
     <Button text="6" /> 
    </StackLayout> 
</ScrollView> 
</StackLayout> 
0

嘗試使用Repeater而不是ListView,如https://docs.nativescript.org/cookbook/ui/repeater中所述。以下是如何在ScrollView中包含Repeater的示例,並且可以將整個佈局視爲可滾動。

<ScrollView> 
<StackLayout class="margin"> 
    <Label text="{{ description }}"></Label> 
    <Repeater items="{{ options }}" row="1"> 
     <Repeater.itemTemplate> 
      <StackLayout> 
       <Label text="{{ description }}"></Label> 
      </StackLayout> 
     </Repeater.itemTemplate> 
    </Repeater> 
</StackLayout> 

+0

這是一個邊界[鏈接回答](/ /meta.stackexchange.com/q/8231)。你應該擴大你的答案,在這裏包含儘可能多的信息,並使用鏈接僅供參考。 – FrankerZ