2012-08-28 119 views
0

我被卡在gridview。 我想要一个GridView下面的图像视图来处理点击事件。 基本上我需要的是,当点击这个图像视图按钮(这里imageView_uparrow)它会滑动包含此GridView的布局, ,但是当我在xml中添加imageview(imageView_uparrow)在gridview(imageView_uparrow)下面并运行该项目; gridview在每个网格图标上重复该imageview。 我希望imageview在底部出现一次。这是我的XML。避免在android gridview中重复查看

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="top" > 

    <GridView 
     android:id="@+id/inside_gridView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="50dp" 
     android:layout_marginLeft="14dp" 
     android:layout_marginRight="14dp" 
     android:layout_marginTop="58dp" 
     android:alpha="0.1" 
     android:background="#696969" 
     android:columnWidth="10dp" 
     android:gravity="center" 
     android:numColumns="3" 
     android:padding="4dp" 
     android:scrollbars="vertical" 
     android:stretchMode="columnWidth" > 
    </GridView> 

    <ImageView 
     android:id="@+id/image_insidegrid" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:layout_margin="5dp" 
     android:contentDescription="@string/hello_world" /> 

    <ImageView 
     android:id="@+id/imageView_uparrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="22dp" 
     android:layout_marginRight="20dp" 
     android:contentDescription="@string/hello_world" 
     android:src="@drawable/drop_down_top_arrow" /> 

</RelativeLayout> 

最后的图像视图,即imageView_uparrow继续重复使用gridview项目。 请帮我这个..在此先感谢。

回答

1

嘿我得到了解决方案.. 我保持我的imageView_uparrow在单独的XML和图像,我用它来设置我的网格单独的图标xml.And刚膨胀,并添加到布局。

我修改网格XML是这里

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="top" 
    android:id="@+id/parentRel" 
    > 

    <GridView 
     android:id="@+id/inside_gridView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="50dp" 
     android:layout_marginLeft="14dp" 
     android:layout_marginRight="14dp" 
     android:layout_marginTop="42dp" 
     android:background="@drawable/transperant_background" 
     android:gravity="center" 
     android:numColumns="3" 
     android:padding="0dp" 
     android:scrollbars="vertical" 
     > 
    </GridView> 

</RelativeLayout> 

这是ImageView的(imageView_uparrow)我的XML文件。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_up_arrow_for_gridView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/imageview_up_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="14dp" 
     android:contentDescription="@string/app_name" 

     /> 

</RelativeLayout> 

代码我使用膨胀

Context context; 
RelativeLayout rel; 
ImageView upArrowImage; 

LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 





     context=this; 
    View grid2; 

    rel=(RelativeLayout)findViewById(R.id.parentRel); 

    animate = AnimationUtils.loadAnimation(this, R.anim.slide_up); 
    animate.setAnimationListener(this); 



    LayoutParams lp = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
    lp.setMargins(14, 400, 0, 20); 



    grid2=new View(context); 
    grid2=inflator.inflate(R.layout.gridview_up_arrow_button,null); 

    upArrowImage=(ImageView)grid2.findViewById(R.id.imageview_up_arrow); 

    ((ViewGroup)upArrowImage.getParent()).removeView(upArrowImage); 

    rel.addView(upArrowImage); 
    upArrowImage.setImageResource(R.drawable.drop_down_arrow4); 
    upArrowImage.setLayoutParams(lp);