1
我有一个可扩展列表,里面第一个孩子是Gridview。在这里我有GridView高度切割的问题。我解决了这个问题:Gridview height gets cut。GridView项目不滚动里面Expandable list
现在我得到新的问题是,不能够在一定的高度下滚动gridview项目。我需要在这里添加滚动条,因为gridview项目可能会动态增长。
我能够做到这一点与正常的gridview,但在可扩展列表视图下显示这个烦人的问题。
代码:
<ExpandableListView
android:id="@+id/Explst"
android:layout_height="400dp"
android:transcriptMode="disabled"
android:layout_width="match_parent"
android:layout_marginTop="0.5dp" />
的GridView在扩展列表自定义布局:
<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" />
定制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);
}
}
}
任何建议/提示/链接是明显的。 我想在xamarin.android c#中,但即使任何java android解决方案也是有帮助的。
谢谢
是的,我已经做到了。展开工作没有任何问题。但无法为该网格项目设置滚动条,这是可扩展列表子项。 – Suchith