2012-08-28 59 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);