2014-04-25 44 views
2

我正在做與ScrollView桌面佈局。在這個代碼GridViewTableLayout但我沒有得到ScrollViewGridView。請幫助我。問題出在GridViewscrollView無法在GridView與TableLayout與滾動查看

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:scrollbars="horizontal" > 

<TableLayout 
    android:id="@+id/TableLayout1" 
    android:layout_width="532dp" 
    android:layout_height="257dp" 
    android:layout_gravity="right" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:scrollbarAlwaysDrawVerticalTrack="true" 
    tools:context=".Intcalc" > 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dp" > 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="To Date" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/edttodate" 
      android:layout_width="160dp" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:inputType="date" 
      android:onClick="selectDate" /> 

     <ImageButton 
      android:id="@+id/imageButton2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="left" 
      android:onClick="selectDate" 
      android:src="@android:drawable/btn_star" /> 
    </TableRow> 
    <GridView 
     android:id="@+id/gridView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:numColumns="3" 
     > 
    </GridView> 

     </TableLayout> 

     </ScrollView> 

回答

0

Gridview已經有一個自己的滾動條,所以如果你再次將它包圍在另一個滾動條內,它將是痛苦的。

+0

如何添加滾動視圖裏面的GridView – Andrio

+0

你不能爲GridView控件或ListView添加滾動視圖,因爲他們已經有內置的滾動功能。 –

+0

好吧,但我沒有得到gridview的滾動 – Andrio

0

第一件事你永遠不會在Android中使用兩個滾動。滾動視圖也提供滾動和網格視圖也提供滾動。在你的情況下,你需要改善你的邏輯是滾動視圖網格視圖。

+0

我使用scrollview tablelayout並在tablerow中插入gridview所以我想scrool主要活動和gridview也 – Andrio

0

我使用這個邏輯感謝您的幫助

  GridView gridView=(GridView)findViewById(R.id.gridView1); 

     gridView.setOnTouchListener(new GridView.OnTouchListener() 
     { 

      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; 
      } 
     });