我有一个自定义的网格视图,其中包含这样的项目。
我希望我的项目可以呈正方形,而且在纵向方向上要填满整个屏幕的宽度,在横向方向上要填满整个屏幕的高度。 效果应该如下图所示:
其中,A是正方形的边长,B是边距(可以为零)。
我认为我应该重写onMeasure方法,但具体应该做些什么呢?
也许有人能帮忙吗?
编辑 好的,我尝试在adapter的getView方法中手动设置项目的宽度和高度,效果不错,但仍然不是我想要的。我怎样才能消除列之间的间隔呢? 如下图所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:longClickable="false"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false"
android:text="0"
android:textSize="60sp" />
</LinearLayout>
我希望我的项目可以呈正方形,而且在纵向方向上要填满整个屏幕的宽度,在横向方向上要填满整个屏幕的高度。 效果应该如下图所示:
![layout](https://istack.dev59.com/UskdC.webp)
编辑 好的,我尝试在adapter的getView方法中手动设置项目的宽度和高度,效果不错,但仍然不是我想要的。我怎样才能消除列之间的间隔呢? 如下图所示:
![enter image description here](https://istack.dev59.com/1BXWn.webp)