Created
September 30, 2015 23:33
-
-
Save TWiStErRob/f8190f1f55ec1e7777fc to your computer and use it in GitHub Desktop.
Make GridView or GridLayoutManager items square.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<net.twisterrob.android.view.SquareFrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@id/adapterRoot" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:layout_margin="@dimen/margin" | |
android:padding="@dimen/margin" | |
> | |
<ImageView | |
android:id="@id/image" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:focusable="false" | |
android:scaleType="fitCenter" | |
/> | |
<ImageView | |
android:id="@id/type" | |
android:layout_width="@dimen/icon_size" | |
android:layout_height="@dimen/icon_size" | |
android:layout_gravity="bottom|end" | |
android:layout_marginRight="@dimen/margin" | |
android:layout_marginBottom="@dimen/margin" | |
android:layout_marginEnd="@dimen/margin" | |
android:scaleType="fitCenter" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.twisterrob.android.view; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.widget.FrameLayout; | |
public class SquareFrameLayout extends FrameLayout { | |
public SquareFrameLayout(Context context) { | |
super(context); | |
} | |
public SquareFrameLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public SquareFrameLayout(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
@Override | |
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
//noinspection SuspiciousNameCombination | |
super.onMeasure(widthMeasureSpec, widthMeasureSpec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice work dude.