2013-09-27 52 views
1

我有一個xml文件,其中UI元素按以下順序排列。我解析的數據被填充在列表視圖,但ListView控件不scrollable.Please幫我無法滾動列表查看

ImageView 
TextView 
imageView 
ListView 
imageView 

layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView_description" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#ffffff" 
     android:focusableInTouchMode="true" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/imageView_now_playing" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:scaleType="fitXY" /> 



     <TextView 
      android:id="@+id/textView_DailyLimit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/imageView_now_playing" 
      android:layout_centerHorizontal="true" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="2dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:layout_below="@+id/button_PlayArea" 
      android:layout_marginTop="20dp" 
      android:background="#ffffff" 
      android:orientation="vertical" > 

      <ListView 
       android:id="@+id/listViewEpisodes" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:cacheColorHint="#000000" 
       android:divider="@android:color/black" 
       android:dividerHeight="5dp" 
       android:textColor="#000000" /> 
     </LinearLayout> 

     <ImageView 
      android:id="@+id/button_Characters" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linearLayout1" 
      android:layout_marginTop="20dp" 
      android:scaleType="fitXY" 
      android:src="@drawable/gallery" /> 

     <ImageView 
      android:id="@+id/button_PlayArea" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView_DailyLimit" 
      android:layout_marginTop="20dp" 
      android:scaleType="fitXY" /> 
    </RelativeLayout> 

</ScrollView> 
+0

。 –

+0

@Ketan能否請你清楚你的答案,我沒有得到它 – onkar

+0

我覺得值得一提的是你爲什麼不應該在ScrollView中放置一個ListView。 1)正如@ prateek指出的那樣是一個用戶體驗問題。 2)是一個技術問題:一個ScrollView允許它的孩子假設它有一個無限的高度(由於它可以滾動,所以它的內容不受它自己的大小的限制)。 ListView的一個強大優勢是視圖回收,這不會發生,因爲ListView會使整個適配器膨脹,因爲它認爲它有足夠的空間來展示它們。 – FunkTheMonk

回答

1
ListView lv = (ListView)findViewById(R.id.myListView); // your listview inside scrollview 
lv.setOnTouchListener(new ListView.OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      int action = event.getAction(); 
      switch (action) { 
      case MotionEvent.ACTION_DOWN: 
       // Disallow ScrollView to intercept touch events. 
       v.getParent().requestDisallowInterceptTouchEvent(true); 
       break; 

      case MotionEvent.ACTION_UP: 
       // Allow ScrollView to intercept touch events. 
       v.getParent().requestDisallowInterceptTouchEvent(false); 
       break; 
      } 

      // Handle ListView touch events. 
      v.onTouchEvent(event); 
      return true; 
     } 
    }); 
如果你想與列表視圖中滾動整個佈局,然後使用列表視圖的頁眉和頁腳視圖
2

你被放置在這裏犯了一個大錯誤Listview裏面Scrollview。作爲頂級父母移除Scrollview和用戶RelativeLayoutListview將滾動。

另外一個UX的建議是永遠不會使用側 彼此爲用戶進行的兩次滾動條目將永遠無法知道,必須 滾動。類似地,你將無法識別試圖滾動的用戶 。

建議


你可以做一兩件事。只需將TextView保留在滾動視圖中,並在其下方保留listview,但不要使整個佈局可滾動。即兩個元素可以滾動,但不是具有可滾動元素的整個屏幕。

+0

這應該是評論。 –

+0

@prateek會使整個佈局滾動嗎? – onkar

+0

@BirajZalavadia我編輯了我的答案,希望它不是一個評論。所以你可以刪除你的downvote :) – Prateek

0

的ListView不需要滾動型裏面,使其滾動的ListView因爲將滾動如果內容太長。

+0

我的textview太大了。因此我已經使其可滾動 – onkar

0

你可以把listview放在scrollview裏面。看到這個https://stackoverflow.com/a/18354096/942224

,並設置列表視圖

的這個值
yourListView.setExpanded(true); 
+0

ExpandableHeightListView listView =(ExpandableHeightListView)findViewById(R.id.expandableHeightlist1); \t \t listView.setAdapter(adapter); \t \t listView.setExpanded(true); 它仍然沒有工作:( – onkar

+0

有你的android設置:可調焦=「假」 安卓:?滾動條=「無」這個 –

+0

有,我有,設置其屬性 – onkar