Created
March 29, 2018 10:15
-
-
Save DSdatsme/0d97bbbc45fca0975a70dadeb5138c80 to your computer and use it in GitHub Desktop.
this is for generating square images which always takes width form parent and sets height equal to width
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
public class MySquareImages extends android.support.v7.widget.AppCompatImageView { | |
public MySquareImages(Context context) { | |
super(context); | |
} | |
public MySquareImages(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public MySquareImages(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
int width = getMeasuredWidth(); | |
setMeasuredDimension(width, width); | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<com.example.dsdatsme.instaclone.Utils.MySquareImages | |
android:src="@drawable/img5" | |
android:layout_width="0dp" | |
android:layout_height="0dp" | |
android:scaleType="centerCrop" | |
android:layout_weight="1"/> | |
<com.example.dsdatsme.instaclone.Utils.MySquareImages | |
android:src="@drawable/img5" | |
android:layout_width="0dp" | |
android:layout_height="0dp" | |
android:scaleType="centerCrop" | |
android:layout_weight="1"/> | |
<com.example.dsdatsme.instaclone.Utils.MySquareImages | |
android:src="@drawable/img5" | |
android:layout_width="0dp" | |
android:layout_height="0dp" | |
android:scaleType="centerCrop" | |
android:layout_weight="1"/> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment