I have a expandable list,inside that first child is Gridview. here i had issue of gridview height cut. that i solved by using this solution: Gridview height gets cut.
Now i'm getting new issue is, not able to scroll the gridview item under some fixed height. I need to add scroller here because there is a possibility that gridview item can grow dynamically.
i'm able to do this with normal gridview, but showing this annoying issue under expandable listview.
code:
<ExpandableListView
android:id="@+id/Explst"
android:layout_height="400dp"
android:transcriptMode="disabled"
android:layout_width="match_parent"
android:layout_marginTop="0.5dp" />
Gridview in expandable list custom layout:
<mynamespace.ExpandableHeightGridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="20dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:isScrollContainer="false"
android:gravity="center" />
custom expandableheightgridview.cs
mynamespace
{
public class ExpandableHeightGridView :GridView
{
bool _isExpanded = false;
public ExpandableHeightGridView (Context context) : base (context)
{
}
public ExpandableHeightGridView (Context context, IAttributeSet attrs) : base (context, attrs)
{
}
public ExpandableHeightGridView (Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle)
{
}
public bool IsExpanded {
get { return _isExpanded; }
set { _isExpanded = value; }
}
protected override void OnMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
if (IsExpanded) {
int expandSpec = MeasureSpec.MakeMeasureSpec (View.MeasuredSizeMask, MeasureSpecMode.AtMost);
base.OnMeasure (widthMeasureSpec, expandSpec);
var layoutParameters = this.LayoutParameters;
layoutParameters.Height = this.MeasuredHeight;
} else {
base.OnMeasure (widthMeasureSpec, heightMeasureSpec);
}
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
Any suggestion/hints/links are appreciable. I'm trying this in xamarin.android c#, but even any java android solutions are also helpful.
Thanks