2012-08-28 4 views
0

Я застреваю в gridview. Я хочу, чтобы изображение под Gridview обрабатывало событие щелчка. В основном то, что мне нужно, когда нажимает на эту кнопку просмотра изображения (здесь imageView_uparrow), она сдвигает макет, содержащий этот gridview, , но когда я добавляю изображение (imageView_uparrow) под gridview (imageView_uparrow) в xml и запускаю проект; gridview повторяет это изображение на каждом значке сетки. Я хочу, чтобы изображение было показано однажды внизу. Вот мой XML.Избегайте повторения вида в андроиде 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> 

Последнее изображение в i.e 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> 

Это мой XML-файл для ImageView (imageView_uparrow).

<?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); 
Смежные вопросы