开发者

Scrolling a GridView with only Buttons

I have a GridView with only Buttons in it. The Buttons should be able to be pressed (working). But if I want to scroll the gridview with many items in it it is not working on my HTC Desire but it is possible in emulator.

My GridView:

<GridView  
  android:id="@+id/gv_control_group" 
  android:layout_height="wrap_content"
  android:isScrollContainer="true" 
  android:layout_width="fill_parent"
  android:numColumns="auto_fit"
  android:verticalSpacing="10dp"
  android:horizontalSpacing="10dp"
  android:stretchMode="columnWidth"
  android:gravity="center"
  android:scrollingCache="true"
/>

GridViewItem:

<LinearLayout 
  android:id="@+id/gi_socket"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:gravity="center_horizontal">

<Button
   android:id="@+id/gi_btn"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:drawableTop="@drawable/green"
/>
</LinearLayout>

Second Question: How can I make the GridView show more items next to each other when turning the device. Now it just stretches two items to the whole width...

android:stretchMode="none"

is n开发者_如何学Goot working

edit:

It's a problem with Android 2.2 In Emulator with 2.1 everything works. But with Android 2.2 scrolling is not possible anymore ... Is there a workaround to make it scrolling in 2.2?


solved

the problem was that the there was a Button above the GridView, both were in a LinearLayout. The LinearLayout self was in a ScrollView. So the ScrollView prevented the GridView from behaving correctly (But not with Android 2.1!)


You can implement your own GridView and override onInterceptTouchEvent and onTouchEvent according to what you need, so you can detect if its a move/scroll event and leave the event in your GridView or if it is a click in your buttons pass the event to them.

I hope this helps

EDIT: regarding your second question, you can use for example:

android:stretchMode="spacingWidthUniform"
android:numColumns="auto_fit"
android:columnWidth="100dip"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜