2015-02-24 2 views
0

Привет Я работаю с пользовательским GridView.Сетка Элементы меняются при прокрутке

GridView размещен в следующем файле xml/layout.

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

    <View 
     android:id="@+id/music_home_ad_view" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" /> 

    <ScrollView 
     android:id="@+id/music_home_root_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ScrollView> 

    <FrameLayout 
     android:id="@+id/music_home_promo_frame" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/music_home_promo_height" 
     android:layout_marginTop="20dp" > 

     <android.support.v4.view.ViewPager 
      android:id="@+id/music_home_promo_pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <com.raaga.home.CirclePageIndicator 
      android:id="@+id/music_home_page_indicator" 
      android:layout_width="fill_parent" 
      android:layout_height="30dp" 
      android:layout_gravity="bottom" 
      android:padding="10dp" /> 
    </FrameLayout> 

    <GridView 
     android:id="@+id/music_home_grid_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/music_home_promo_frame" 
     android:numColumns="3" > 
    </GridView> 

</RelativeLayout> 

Элемент GridView содержит следующие представления

music_grid_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" 
    > 

    <ImageView 
     android:id="@+id/music_grid_image" 
     android:layout_width="60dp" 
     android:layout_height="70dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerInParent="true" 
     android:layout_marginTop="10dp" 
     android:src="@drawable/new_releases" 

     /> 

    <TextView 
     android:id="@+id/music_grid_category_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/music_grid_image" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:text="New Releases" 
     android:textColor="@color/text_white" 
     /> 

</RelativeLayout> 

я использовал пользовательский класс адаптера и затем this link

MusicCategoryAdapter.java

public class MusicCategoryAdapter extends BaseAdapter{ 

    ArrayList<Integer> categoryImageList; 
    ArrayList<String> categoryNameList; 
    Context mContext; 

    public MusicCategoryAdapter(Context mContext, ArrayList<Integer> categoryImageList, ArrayList<String> categoryNameList) { 

     this.mContext= mContext; 
     this.categoryImageList = categoryImageList; 
     this.categoryNameList = categoryNameList; 

    } 


    @Override 
    public int getCount() { 

     //send the list length 
     return categoryImageList.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return null; 
    } 

    @Override 
    public long getItemId(int position) { 
     return 0; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     GridHolder holder; 
     View grid = convertView; 
      LayoutInflater inflater = (LayoutInflater) mContext 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       if (convertView == null) { 
       grid = new View(mContext); 
       convertView = inflater.inflate(R.layout.music_grid_item, null); 
       holder = new GridHolder(); 
      holder.categoryTitle = (TextView) convertView.findViewById(R.id.music_grid_category_name); 
      holder.categoryImage = (ImageView)convertView.findViewById(R.id.music_grid_image); 
      holder.categoryTitle.setText(categoryNameList.get(position)); 
      holder.categoryImage.setImageResource(categoryImageList.get(position)); 
       convertView.setTag(holder); 
       } else { 
       holder = (GridHolder) convertView.getTag(); 
       } 
      return convertView; 

    } 

    public class GridHolder{ 
     ImageView categoryImage; 
     TextView categoryTitle; 
    } 
} 

У меня возникла проблема с тем, что элементы повторяются, изменяя положение при прокрутке.

Может ли кто-нибудь помочь в решении этой проблемы? Какую ошибку я сделал в этом?

ответ

0

Поместите прокрутку в начало относительной компоновки и завершите тег в конце относительной компоновки. Это сделало бы ваш весь макет прокручиваемым, и вы преодолеете проблему.

+0

kumar такой же результат последующий изменение сделал –

Смежные вопросы