适配器内的GridView适配器 [英] Gridview adapter within an adapter
问题描述
在参考<一个href=\"http://stackoverflow.com/questions/17471547/gridview-in-a-gridview?noredirect=1#comment25390531_17471547\">this题。我已经碰了壁,我有我的两个适配器设置和我的XML文件都很好地一字排开。在我的活动我已经把我的内容视图包含顶部gridview的主要XML。在适配器我已经联系我的ImageView到GridView。
问题是我怎么去设置 grid_item.xml
作为我的内心适配器内容查看,这样我可以下一个图像视图链接到XML <? / p>
这是我的XML文件中的命令:
main_layout.xml
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直&GT; &LT; GridView控件
机器人:ID =@ + ID / gridview_main
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_margin =5SP
机器人:columnWidth时=60SP
机器人:比重=中心
机器人:horizontalSpacing =10SP
机器人:为numColumns =2
机器人:stretchMode =columnWidth时
机器人:verticalSpacing =10SP
机器人:clipChildren =真/&GT;&LT; / LinearLayout中&GT;
grid_item.xml
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直&GT; &LT; ImageView的
机器人:ID =@ + ID / category_main_pic
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ arrow_left_dark/&GT; &LT; GridView控件
机器人:ID =@ + ID / gridview_item
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_margin =5SP
机器人:columnWidth时=90sp
机器人:比重=中心
机器人:horizontalSpacing =10SP
机器人:为numColumns =2
机器人:stretchMode =columnWidth时
机器人:verticalSpacing =10SP
机器人:clipChildren =真/&GT;
&LT; / LinearLayout中&GT;
item_grid_image.xml
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直&GT; &LT; ImageView的
机器人:ID =@ + ID / item_main_pic
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ arrow_left_dark/&GT;&LT; / LinearLayout中&GT;
我需要让我的grid_item.xml的内容我内心的适配器。任何想法?
截至高达取决于孩子的数量设置的意见(带图像视图)。添加一个GridView到每个GridView控件元素最终搞乱滚动。)
In reference to this question. I have hit a wall, I have both of my adapters set up, and my xml files are nicely lined up. In my activity I have set my content view to the main xml which contains the top gridview. In the adapter I have linked my Imageview to the gridview.
The problem is how do I go about setting the grid_item.xml
as my contentview for the inner adapter so that I can link the next image view to the xml?
These are my xml files in order:
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/gridview_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:columnWidth="60sp"
android:gravity="center"
android:horizontalSpacing="10sp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10sp"
android:clipChildren="true" />
</LinearLayout>
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/category_main_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_left_dark" />
<GridView
android:id="@+id/gridview_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:columnWidth="90sp"
android:gravity="center"
android:horizontalSpacing="10sp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10sp"
android:clipChildren="true" />
</LinearLayout>
item_grid_image.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/item_main_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_left_dark" />
</LinearLayout>
I need to get the content of my grid_item.xml for my inner adapter. Any ideas?
Ended up settings views (views with images) dependant on the amount of children. Adding a gridview to each gridview element ended up messing up scrolling :).
这篇关于适配器内的GridView适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!