2017-09-21 11 views
-1

グリッドビュー内のアイテムが重なり合うか上下に動くことがありますが、再度スクロールすると修正されます。残念ながら、ここで新しいので、イメージを提供できません。私は何かコード内でやっています。しかし、listViewを使うときは問題ありません。 GridViewのためグリッドビューがスクロール中に間違って表示される

のXml:あなたはその他の詳細が必要な場合はお問い合わせください

[public class GameAdapter extends ArrayAdapter<GameNews> { 


    public GameAdapter(@NonNull Context context, List<GameNews> gameNews){ 
     super(context, 0, gameNews); 
     if(gameNews == null) 
     { 
      return; 
     } 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     GameNews currentNews = getItem(position); 

     // Check if the existing view is being reused, otherwise inflate the view 
     View listItemView = convertView; 
     if (listItemView == null) { 
      listItemView = LayoutInflater.from(getContext()).inflate(
        R.layout.grid_item, parent, false); 
      final ViewHolder v = new ViewHolder(); 

      // Find the TextView in the grid_item.xml layout with the ID version_name 

      v.Heading = (TextView) listItemView.findViewById(R.id.title); 
      v.description = (TextView) listItemView.findViewById(R.id.description); 
      v.newsImage = (ImageView) listItemView.findViewById(R.id.image) ; 
      v.source = (TextView) listItemView.findViewById(R.id.source); 
      v.time = (TextView) listItemView.findViewById(R.id.time); 
      v.menuButton = (Button) listItemView.findViewById(R.id.popup); 
      listItemView.setTag(v); 


      v.menuButton.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 

        PopupMenu popup = new PopupMenu(getContext(),view); 
        MenuInflater inflater = popup.getMenuInflater(); 
        inflater.inflate(R.menu.popup_menu, popup.getMenu()); 
        popup.show(); 

       } 
      }); 
     } 

ViewHolder viewHolder = (ViewHolder) listItemView.getTag(); 

     //Setting title to current news title 
     viewHolder.Heading.setText(currentNews.getTitle()); 
     viewHolder.description.setText(currentNews.getDescription()); 
     viewHolder.newsImage.setTag(currentNews.getphotoUrl()); 
viewHolder.source.setText(currentNews.getSource()); 
     viewHolder.time.setText(currentNews.getTime()); 
     // Picasso.with(getContext()).load(currentNews.getphotoUrl()).into(viewHolder.newsImage); 


     if (URLUtil.isValidUrl(currentNews.getphotoUrl())) { 
      Picasso.with(getContext()) 
        .load(currentNews.getphotoUrl()) 
        .resize(350,300) 
        .tag(tag) 
        .error(R.drawable.placeholder) 
        .placeholder(R.drawable.placeholder) 
        .into(viewHolder.newsImage); 

     } else { 
      Picasso.with(getContext()) 
        .load(R.drawable.right_line) 
        .resize(350,300) 
        .tag(tag) 
        .noPlaceholder() 
        .into(viewHolder.newsImage); 
     } 

     return listItemView; 
    } 




    public static class ViewHolder { 
     TextView Heading; 
     TextView description; 
     ImageView newsImage; 
     TextView source; 
TextView time; 
Button menuButton; 


    } 
}][1] 

:ここ

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.android.gametalks.MainActivity" 
    android:background="@color/card_white"> 

    <GridView 
android:columnWidth="10dp" 
       android:numColumns="2" 
       android:id="@+id/listView" 
       android:dividerHeight="0dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:verticalSpacing="30dp" 
       ></GridView> 

    <ProgressBar 
     android:id="@+id/progress_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true"/> 

</RelativeLayout> 

アダプタです。

+0

あなたはこの記述があいまいであるように何かを見ることができるように、いくつかのコードまたは要点へのリンクを提供する必要があります。 –

答えて

0

これは、コンテンツをラップするためにgridViewアイテムのサイズを設定し、異なるアイテムが異なるサイズに設定されているために発生しました。これは、gridViewの不安定さを引き起こしました。gridViewのアイテムに固定されたdpサイズ。そして今それは問題ありません

関連する問題