To do this: You need to use a GridView
with two columns, you could use a StaggeredGridView
( etsy StagerredGridView) if the images have different heights, but this is not the case.
To make a square image, I suggest this subclass of ImageView:
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); //Snap to width
}
}
It forces the height of the image to be the same length as the width.
For the layout of the view, I recommend the following:
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="columnWidth"
android:numColumns="2" />
For the layout of the item within the GridView:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SquareImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Fulaninho"
android:textColor="@color/white"
android:ellipsize="end"
android:lines="2"
android:gravity="center_vertical"
android:fontFamily="sans-serif-light"
android:background="#99000000" />
</FrameLayout>
In this case the image will be scaled while maintaining the Aspect Ratio. Of course some details are missing, but the bulk is that.
Ah, I did not comment on adding images dynamically in the GridView and how to access the camera features, but I believe the question was about the layout.