应用程序的图片:
我是初学者,我不知道如何修复这个bug。 图像应该一个接一个地出现,宽度应该是 Match_Parent 。 但每张图片后都有一个cardView Space。我没有这背后的原因。 我使用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 :(得分: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">
答案 1 :(得分:0)
尝试此更改LinearLayout
高度为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>