0

画像にrecyclerViewに繰り返している:ブランクCardViewは、フラグメントアプリの

enter image description here

私は初心者です、私はこのバグを修正する方法がわかりません。 画像が順番に来るはずです。幅はMatch_Parentです。 しかし、各画像の後にcardViewスペースがあります。私はその背後にある理由はありません。 私は、LinearLayoutMangaerを使用してrecyclerViewにデータを設定しました。最初はGridLayoutManagerを試してみましたが、結果は同じでした。

[ビューの画像]

fragmentWall.java

public class fragmentWall extends Fragment { 

private String title; 
private int page; 
public DatabaseReference databaseReference; 

private RecyclerView recyclerView; 

ImageView imageView; 
public static fragmentWall newInstance(int page, String title) { 
    fragmentWall fragmentp = new fragmentWall(); 
    Bundle args = new Bundle(); 
    args.putInt("someInt", page); 
    args.putString("someTitle", title); 
    fragmentp.setArguments(args); 
    return fragmentp; 
} 

// Store instance variables based on arguments passed 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

// Inflate the view for the fragment based on layout XML 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_fragment_wall, container, false); 
    //TextView tvLabel = (TextView) view.findViewById(R.id.tvpopular); 
    //tvLabel.setText(page + " -- " + title); 

    databaseReference = FirebaseDatabase.getInstance().getReference(); 

    imageView = (ImageView) view.findViewById(R.id.imagerow); 
    LinearLayoutManager layoutManager 
      = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false); 
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerViewWall); 
    recyclerView.setHasFixedSize(true); 
    recyclerView.setLayoutManager(layoutManager); 
    return view; 
} 



@Override 
public void onStart() { 
    super.onStart(); 

    FirebaseRecyclerAdapter<image_details, ImageViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<image_details, ImageViewHolder>(
      image_details.class, 
      R.layout.rowwall, 
      ImageViewHolder.class, 
      databaseReference 
    ) { 
     @Override 
     protected void populateViewHolder(ImageViewHolder viewHolder, final image_details model, int position) { 

      //viewHolder.setDate(model.getdate().toString()); 
      viewHolder.setImage(getContext(),model.geturl()); 
      viewHolder.linearLayout.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        String url= null; 
        Intent intent = new Intent(getContext(), SetWallpaper.class); 
        intent.putExtra("url", model.geturl()); 
        startActivity(intent); 
        //Toast.makeText(getApplicationContext(), "URL is: "+model.geturl(), Toast.LENGTH_LONG).show(); 
       } 
      }); 
     } 
    }; 


    recyclerView.setAdapter(firebaseRecyclerAdapter); 
} 

public static class ImageViewHolder extends RecyclerView.ViewHolder{ 

    View mView; 
    public LinearLayout linearLayout; 

    public ImageViewHolder(View itemView) { 
     super(itemView); 
     mView=itemView; 
     linearLayout=(LinearLayout)itemView.findViewById(R.id.linearLayoutWall); 
    } 


    public void setImage (Context ctx, String Url){ 
     ImageView post_image = mView.findViewById(R.id.imagerow); 
     Picasso.with(ctx).load(Url).into(post_image); 
    } 
} 
} 

fragment_fragment_wall.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.souravkumar.wallpaper.fragmentWall"> 

<!-- TODO: Update blank fragment layout --> 

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/recyclerViewWall"> 

</android.support.v7.widget.RecyclerView> 

rowwall.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="250dp"> 

    <LinearLayout 
     android:id="@+id/linearLayoutWall" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/imagerow" 
      android:layout_width="match_parent" 
      android:layout_height="250dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/ic_launcher" /> 


    </LinearLayout> 
</android.support.v7.widget.CardView> 
</LinearLayout> 

答えて

0

wrap_content

rowwall.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content"> 
<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="250dp"> 

    <LinearLayout 
     android:id="@+id/linearLayoutWall" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/imagerow" 
      android:layout_width="match_parent" 
      android:layout_height="250dp" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/ic_launcher" /> 


    </LinearLayout> 
</android.support.v7.widget.CardView> 
LinearLayout身長この変更をお試しください

0

変更あなたのrowwall.xmlの高さ:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="wrap_content">