I studied all related questions here and still can't solve this. I have a GridView with custom adapter. This GridView should show square items in two columns. I made a SquareLinearLayout class for item layout:
public class SquareLinearLayout extends LinearLayout {
public SquareLinearLayout(Context context) {
super(context);
}
public SquareLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
GridLayout adapter inflate view here:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.category_entry, parent, false);
}
if (convertView != null) {
((TextView) convertView.findViewById(R.id.category_name)).setText(getItem(position).Name());
}
return convertView;
}
And item:
<xxx.SquareLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:background="@color/colorPrimaryTransparent"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/category_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
</LinearLayout>
</xxx.SquareLinearLayout>
And my layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="@+id/categories"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:scrollbars="vertical"/>
</RelativeLayout>
After starting GridView shows items 6 full-sized items and scrollbar thumb. Then thumb dissapears. And there is no any scrollbar and I can't scroll it. I tried 3 columns and got 15 visible items without scrollbar. This happens in Android 4 only. Android 5 allow scrolling.
What i'm doing wrong ?