aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-12-20 15:56:48 +0100
committerBananeweizen <bananeweizen@gmx.de>2014-12-20 15:56:48 +0100
commit74daa3ebbf94a66b47149ba0428f2c4af838aa15 (patch)
treead3a3bed847006905f15f88f0c8278257ed2cabf /main/src/cgeo/geocaching/ui
parente606e1512d3e600e5beab2442e6095c9d08c989b (diff)
downloadcgeo-74daa3ebbf94a66b47149ba0428f2c4af838aa15.zip
cgeo-74daa3ebbf94a66b47149ba0428f2c4af838aa15.tar.gz
cgeo-74daa3ebbf94a66b47149ba0428f2c4af838aa15.tar.bz2
refactoring: replace dynamically created attribute views
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r--main/src/cgeo/geocaching/ui/WrappingGridView.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/ui/WrappingGridView.java b/main/src/cgeo/geocaching/ui/WrappingGridView.java
new file mode 100644
index 0000000..2c85887
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/WrappingGridView.java
@@ -0,0 +1,38 @@
+package cgeo.geocaching.ui;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.GridView;
+
+/**
+ * GridView that will adjust its height to really use wrap_content. The standard GridView only shows one line of items.
+ *
+ * @see <a href="https://gist.github.com/runemart/9781609">https://gist.github.com/runemart/9781609</a>
+ *
+ */
+public class WrappingGridView extends GridView {
+
+ public WrappingGridView(final Context context) {
+ super(context);
+ }
+
+ public WrappingGridView(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public WrappingGridView(final Context context, final AttributeSet attrs, final int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
+ int heightSpec = heightMeasureSpec;
+ if (getLayoutParams().height == android.view.ViewGroup.LayoutParams.WRAP_CONTENT) {
+ // The two leftmost bits in the height measure spec have
+ // a special meaning, hence we can't use them to describe height.
+ heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
+ }
+ super.onMeasure(widthMeasureSpec, heightSpec);
+ }
+
+} \ No newline at end of file