Текущий вид сетки
Я хочу, чтобы 3-е изображение заняло пустое пространство. Сетка выглядит хорошо, когда высота изображений равна, но когда она неравна, она отображается пустой, чтобы соответствовать высоте следующих изображений. я просто хочу, чтобы изображение, показанное ниже, появилось и заполнило пространство.
Адаптер
public class Adapter extends BaseAdapter {
Context context;
int logos[];
LayoutInflater inflter;
public Adapter(Context applicationContext, int[] logos) {
this.context = applicationContext;
this.logos = logos;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return logos.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.custom_grid, null); // inflate the layout
ImageView icon = view.findViewById(R.id.icon); // get the reference of ImageView
icon.setImageResource(logos[i]); // set logo images
return view;
}
}
Пользовательский вид
<?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="wrap_content"
android:padding="1dp"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:scaleType="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/logo" />
</LinearLayout>
XML
<LinearLayout
android:padding="5dp"
android:orientation="vertical"
android:background="@color/white"
android:layout_below="@id/appbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:stretchMode="columnWidth"
android:numColumns="2"
android:id="@+id/grid"
android:gravity="center"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Java
GridView mGridView = findViewById(R.id.grid);
Adapter customAdapter = new Adapter(getApplicationContext(), logos);
mGridView.setAdapter(customAdapter);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),position,Toast.LENGTH_LONG).show();
}
});
Обычно используется представление рециркулятора, но необходимы столбцы, поэтому переключились на просмотр сетки. Я нашел источники для того, чтобы сделать изображения равными по высоте. Но я не хочу этого. Я не хочу, чтобы он сохранял пропорции, а просто заполнял все доступное пространство