To do this: You need to use one GridView
with two columns, 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 image height 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 item layout within 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 keeping the Aspect Ratio. Of course some details are missing, but the thick one is this one.
Ah, I didn’t comment on adding images dynamically in Gridview and how to access camera features, but I believe the question was about the layout.
@bigown when a question is solved I don’t need to put Solved in the title?
– Lucas Santos
No. This is not recommended here, pleocontrary. Putting "solved" is common in forums, but we are a question and answer site. What is ideal, but not mandatory, is to choose the right answer, as you did. Evidently will not choose an answer if none can be considered as the best posted. You can even choose your answer if you think it is the best one. Or you can choose someone else even if you have given your answer. Goes from the specific case.
– Maniero
Okay. I understand the difference. Thank you for the warning.
– Lucas Santos