我有一个可扩展的列表视图。我想将不同的数据放在子视图中并使它们可滚动。目前我的可扩展列表视图正在滚动而不是子滚动。我怎样才能限制它并满足要求?
gridcustom layout:
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/item_Image"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@color/accent"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="Image"
android:gravity="center"
android:layout_below="@+id/item_Image"
android:layout_alignParentBottom="true" />
</LinearLayout>
my grid:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_scroll_view"
android:layout_width="match_parent"
android:layout_height="250dp">
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="120dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:gravity="center"/>
</LinearLayout>
Expandable listview adapter:
using System;
using Android.Widget;
using System.Collections.Generic;
using Android.App;
using Android.Views;
namespace Sasken
{
public class ExpandableListAdapter :BaseExpandableListAdapter
{
Activity _context;
List<GridDataClass> _lstGrdData;
ImageAdapter imageAdaptor;
LayoutInflater layoutInflater;
public ExpandableListAdapter (Activity context, List<GridDataClass> lstGridData)
{
this._context = context;
this.layoutInflater = layoutInflater;
this._lstGrdData = lstGridData;
}
public override Java.Lang.Object GetChild (int groupPosition, int childPosition)
{
return true;
}
public override long GetChildId (int groupPosition, int childPosition)
{
return childPosition;
}
public override View GetChildView (int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
// string childText = (string) GetChild(groupPosition, childPosition);
// if (convertView == null) {
// convertView = _context.LayoutInflater.Inflate (Resource.Layout.ListItemCustomLayout, null);
// }
// TextView txtListChild = (TextView) convertView.FindViewById(Resource.Id.lblListItem);
// txtListChild.Text=childText;
View v = null;
if (groupPosition == 0) {
v = View.Inflate (_context, Resource.Layout.expandable_Child_Layout, null);
GridView grid = (GridView)v.FindViewById (Resource.Id.gridview);
grid.SetAdapter (new ImageAdapter (this._context, _lstGrdData));
}
if (groupPosition == 1) {
v = View.Inflate (_context, Resource.Layout.expandable_child_1_layout, null);
TextView txtView = (TextView)v.FindViewById (Resource.Id.lblListItem);
txtView.Text = "Test";
txtView.TextSize = 15f;
}
if (groupPosition == 2) {
v = View.Inflate (_context, Resource.Layout.expandable_child_2_layout, null);
TextView txtView = (TextView)v.FindViewById (Resource.Id.lblListItem);
txtView.Text = "Test";
txtView.TextSize = 15f;
}
v.Invalidate ();
return v;
}
public override int GetChildrenCount (int groupPosition)
{
return 1;
}
public override Java.Lang.Object GetGroup (int groupPosition)
{
return null;
}
public override int GroupCount {
get {
return 3;
}
}
public override long GetGroupId (int groupPosition)
{
return 0;
}
public override View GetGroupView (int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
View v = _context.LayoutInflater.Inflate (Resource.Layout.HeaderCustomLayout, null); //infalInflater.inflate(R.layout.list_group, null);
TextView lblListHeader = (TextView)v.FindViewById (Resource.Id.lblListHeader);
if (groupPosition == 0) {
lblListHeader.Text = "QUICK ITEMS";
lblListHeader.SetTypeface (null, Android.Graphics.TypefaceStyle.Bold);
}
if (groupPosition == 1) {
lblListHeader.Text = "PRODUCT LOOKUP";
lblListHeader.SetTypeface (null, Android.Graphics.TypefaceStyle.Bold);
}
if (groupPosition == 2) {
lblListHeader.Text = "NON MARCHANDISE";
lblListHeader.SetTypeface (null, Android.Graphics.TypefaceStyle.Bold);
}
if (groupPosition == 3) {
lblListHeader.Text = "QUICK ITEMS";
lblListHeader.SetTypeface (null, Android.Graphics.TypefaceStyle.Bold);
}
v.Invalidate ();
return v;
}
public override bool HasStableIds {
get {
return false;
}
}
public override bool IsChildSelectable (int groupPosition, int childPosition)
{
return true;
}
class ViewHolderItem :Java.Lang.Object
{
}
}
}
Image custom adaptor::
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Sasken
{
[Activity (Label = "ImageAdaptor")]
public class ImageAdapter : BaseAdapter
{
Activity _context;
List<GridDataClass> _lstGridData;
ImageView imageView;
TextView textView;
public ImageAdapter (Activity c, List<GridDataClass> lstGridData)
{
_context = c;
_lstGridData = lstGridData;
}
public override int Count {
get { return _lstGridData.Count; }
}
public override Java.Lang.Object GetItem (int position)
{
return null;
}
public override long GetItemId (int position)
{
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public override View GetView (int position, View convertView, ViewGroup parent)
{
if (convertView == null) { // if it's not recycled, initialize some attributes
convertView = _context.LayoutInflater.Inflate (Resource.Layout.GridCustomLayout, parent, false);
imageView = (ImageView)convertView.FindViewById (Resource.Id.item_Image);
textView = (TextView)convertView.FindViewById (Resource.Id.item_name);
// convertView.LayoutParameters = new GridView.LayoutParams (150,150);
// //convertView.SetScale (ImageView.ScaleType.CenterCrop);
// convertView.SetPadding (2, 2, 2, 2);
}
imageView.SetImageResource (_lstGridData [position].intImgSource);
textView.Text = (_lstGridData [position].strImgName);
return convertView;
}
}
public class GridDataClass
{
public GridDataClass (int item_value = 1, string item_name = "Temporary Id")
{
strImgName = item_name;
intImgSource = item_value;
}
public string strImgName{ get; set; }
public int intImgSource{ get; set; }
}
}