Guest User

Untitled

a guest
May 15th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. Gridview height gets cut
  2. <GridView
  3. android:id="@+id/myId"
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content"
  6. android:gravity="center"
  7. android:horizontalSpacing="2dp"
  8. android:isScrollContainer="false"
  9. android:numColumns="4"
  10. android:stretchMode="columnWidth"
  11. android:verticalSpacing="20dp" />
  12.  
  13. <?xml version="1.0" encoding="utf-8"?>
  14. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:orientation="vertical"
  18. android:minHeight="?android:attr/listPreferredItemHeight"
  19. >
  20. <ImageView
  21. android:id="@+id/appItemIcon"
  22. android:layout_width="fill_parent"
  23. android:layout_height="wrap_content"
  24.  
  25. android:src="@android:drawable/ic_dialog_info"
  26. android:scaleType="center"
  27. >
  28. </ImageView>
  29.  
  30.  
  31. <TextView
  32. android:id="@+id/appItemText"
  33. android:layout_width="fill_parent"
  34. android:layout_height="wrap_content"
  35.  
  36. android:text="My long application name"
  37. android:gravity="center_horizontal"
  38. android:textAppearance="?android:attr/textAppearanceSmall" />
  39.  
  40.  
  41. </LinearLayout>
  42.  
  43. package com.example;
  44. public class ExpandableHeightGridView extends GridView
  45. {
  46.  
  47. boolean expanded = false;
  48.  
  49. public ExpandableHeightGridView(Context context)
  50. {
  51. super(context);
  52. }
  53.  
  54. public ExpandableHeightGridView(Context context, AttributeSet attrs)
  55. {
  56. super(context, attrs);
  57. }
  58.  
  59. public ExpandableHeightGridView(Context context, AttributeSet attrs,
  60. int defStyle)
  61. {
  62. super(context, attrs, defStyle);
  63. }
  64.  
  65. public boolean isExpanded()
  66. {
  67. return expanded;
  68. }
  69.  
  70. @Override
  71. public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
  72. {
  73. // HACK! TAKE THAT ANDROID!
  74. if (isExpanded())
  75. {
  76. // Calculate entire height by providing a very large height hint.
  77. // But do not use the highest 2 bits of this integer; those are
  78. // reserved for the MeasureSpec mode.
  79. int expandSpec = MeasureSpec.makeMeasureSpec(
  80. Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
  81. super.onMeasure(widthMeasureSpec, expandSpec);
  82.  
  83. ViewGroup.LayoutParams params = getLayoutParams();
  84. params.height = getMeasuredHeight();
  85. }
  86. else
  87. {
  88. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  89. }
  90. }
  91.  
  92. public void setExpanded(boolean expanded)
  93. {
  94. this.expanded = expanded;
  95. }
  96. }
  97.  
  98. <com.example.ExpandableHeightGridView
  99. android:id="@+id/myId"
  100. android:layout_width="wrap_content"
  101. android:layout_height="wrap_content"
  102. android:gravity="center"
  103. android:horizontalSpacing="2dp"
  104. android:isScrollContainer="false"
  105. android:numColumns="4"
  106. android:stretchMode="columnWidth"
  107. android:verticalSpacing="20dp" />
  108.  
  109. mAppsGrid = (ExpandableHeightGridView) findViewById(R.id.myId);
  110. mAppsGrid.setExpanded(true);
Advertisement
Add Comment
Please, Sign In to add comment