Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 图像视图(RecyclerView)之间的大空间_Android_Android Recyclerview_Imageview - Fatal编程技术网

Android 图像视图(RecyclerView)之间的大空间

Android 图像视图(RecyclerView)之间的大空间,android,android-recyclerview,imageview,Android,Android Recyclerview,Imageview,我正在尝试创建一个墙纸应用程序,但是我遇到了一个问题,recyclerView照片之间有一个很大的空间,像这样隔开 照片 我不知道为什么会以这种格式出现宽度大于高度 爪哇: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { List<String> movieList = new ArrayList&l

我正在尝试创建一个墙纸应用程序,但是我遇到了一个问题,
recyclerView
照片之间有一个很大的空间,像这样隔开 照片

我不知道为什么会以这种格式出现宽度大于高度

爪哇:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    List<String> movieList =  new ArrayList<>();
    movieList.add("https://lh3.ggpht.com/-yKfQjOKJq9HcsOqzdCfpP-POQgEtJb43RZAQjEn10XiOEgM_CBgndV7stWe67wXiCq5=h900");
    movieList.add("http://www.botherland.com/wp-content/uploads/2017/04/Samsung-Galaxy-S4-Black-Edition-Wallpaper-16.jpg");
    movieList.add("http://www.botherland.com/wp-content/uploads/2017/04/Samsung-Galaxy-S4-Black-Edition-Wallpaper-5.jpg");
    movieList.add("http://www.androidhive.info/wp-content/uploads/2016/01/android-recycler-view-example.png");
    movieList.add("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTygBxBtnlvqcQR5GmFCvD1rvPUJJeHLm6lH2zckeYQ6XScoutwN0NgaG0");
    movieList.add("http://www.botherland.com/wp-content/uploads/2017/04/Samsung-Galaxy-S4-Black-Edition-Wallpaper-14.jpg");
    View v =  inflater.inflate(R.layout.fragment_art, container, false);
    recyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);
    mAdapter = new MoviesAdapter(movieList,getContext());
    final StaggeredGridLayoutManager stg= new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(stg);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);
    return v;
}

public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.MyViewHolder> {
    private List<String> moviesList;
    class MyViewHolder extends RecyclerView.ViewHolder {
        public ImageView pic ;

        public MyViewHolder(View view) {
            super(view);
           pic = (ImageView)view.findViewById(R.id.imageView);
        }
    }
    public Context context;
    int screenWidth,screenHeight;
    MoviesAdapter(List<String> moviesList, Context context) {
        this.moviesList = moviesList;
        this.context=context;
        WindowManager wm = (WindowManager) getActivity().getSystemService(getActivity().WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.picture_item, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
       String pic  = moviesList.get(position);
        Glide.with(context).load(pic).placeholder(R.drawable.j).override(screenWidth/2,screenHeight/4).centerCrop().into(holder.pic);
}
    @Override
    public int getItemCount() {
        return moviesList.size();
    }
}
@覆盖
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
List movieList=new ArrayList();
电影列表。添加(“https://lh3.ggpht.com/-yKfQjOKJq9HcsOqzdCfpP-POQgEtJb43RZAQjEn10XiOEgM_CBgndV7stWe67wXiCq5=h900");
电影列表。添加(“http://www.botherland.com/wp-content/uploads/2017/04/Samsung-Galaxy-S4-Black-Edition-Wallpaper-16.jpg");
电影列表。添加(“http://www.botherland.com/wp-content/uploads/2017/04/Samsung-Galaxy-S4-Black-Edition-Wallpaper-5.jpg");
电影列表。添加(“http://www.androidhive.info/wp-content/uploads/2016/01/android-recycler-view-example.png");
电影列表。添加(“https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTygBxBtnlvqcQR5GmFCvD1rvPUJJeHLm6lH2zckeYQ6XScoutwN0NgaG0");
电影列表。添加(“http://www.botherland.com/wp-content/uploads/2017/04/Samsung-Galaxy-S4-Black-Edition-Wallpaper-14.jpg");
视图v=充气机。充气(R.layout.fragment_艺术,容器,假);
recyclerView=(recyclerView)v.findViewById(R.id.recycler\u视图);
mAdapter=newmoviesadapter(movieList,getContext());
最终StaggedGridLayoutManager stg=新的StaggedGridLayoutManager(2,StaggedGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(stg);
setItemAnimator(新的DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
返回v;
}
公共类MoviesAdapter扩展了RecyclerView.Adapter{
私人名单电影名单;
类MyViewHolder扩展了RecyclerView.ViewHolder{
公众形象图片;
公共MyViewHolder(视图){
超级(视图);
pic=(ImageView)view.findViewById(R.id.ImageView);
}
}
公共语境;
int屏幕宽度,屏幕高度;
MoviesAdapter(列表moviesList,上下文){
this.moviesList=moviesList;
this.context=context;
WindowManager wm=(WindowManager)getActivity().getSystemService(getActivity().WINDOW_服务);
Display Display=wm.getDefaultDisplay();
点大小=新点();
display.getSize(size);
屏幕宽度=大小x;
屏幕高度=尺寸y;
}
@凌驾
公共MyViewHolder onCreateViewHolder(视图组父级,int-viewType){
View itemView=LayoutInflater.from(parent.getContext())
.充气(R.layout.picture_项目,父项,假);
返回新的MyViewHolder(itemView);
}
@凌驾
公共无效onBindViewHolder(MyViewHolder,int位置){
字符串pic=moviesList.get(位置);
使用(上下文)、加载(pic)、占位符(R.drawable.j)、覆盖(屏幕宽度/2、屏幕高度/4)、中心裁剪()插入(holder.pic);
}
@凌驾
public int getItemCount(){
返回moviesList.size();
}
}
xml:

<LinearLayout 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"
android:orientation="vertical"
android:background="#fff"
tools:context="maa.a4kandhdwallpapers.Art">
<!-- TODO: Update blank fragment layout -->
   <android.support.v7.widget.RecyclerView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:id="@+id/recycler_view"/>
 </LinearLayout>

picture_item.xml:

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

   <ImageView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/imageView" />
</LinearLayout>

将图片项目.xml更改为:

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

   <ImageView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/imageView" />
</LinearLayout>


但是如果你的图像高度很大,你也会遇到同样的问题。如果没有问题,我建议您调整高度。

将您的picture\u item.xml更改为:

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

   <ImageView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/imageView" />
</LinearLayout>


但是如果你的图像高度很大,你也会遇到同样的问题。如果没有问题,我建议您调整高度。

您能提供列表项布局文件吗?@pRaNaY请检查我的update@AliILa提供
R.layout.picture\u item.xml
要查看picture\u item布局文件。我想问题出在项目布局文件中?@AliILa在linearlayout.picture\u item.xml中制作包裹内容在R.layout.picture\u高度在R.layout.xml中你能提供你的列表项目布局文件吗?@pRaNaY请检查我的update@AliILa提供
R.layout.picture\u item.xml
要查看picture\u item布局文件。我认为问题出在项目布局文件中?@AliILa在linearlayout layout中制作包裹内容在R.layout.picture\u item.xmlyeap中制作包裹高度在R.layout.picture\u item.xmlyeap中我有这个问题一些照片是规则的,而另一些则是分散的。请看这张照片了解我:你可以固定imageView的高度和宽度,然后自动调整图像为**android:scaleType=“scaleXY”***.Shrestha很抱歉打扰您,但当我在imageView中将这一行
android:scaleType=“scaleXY”
放入时,他给了我无法解析的符号scaleXYOops忽略了这一点。请使用“FIT_XY”而不是“scaleXY”。添加这一行android:adjustViewBounds=“true”是的,我有这个问题一些照片是规则的,其他的是分散的。请查看此图片了解我:您可以固定图像视图的高度和宽度,然后自动调整图像为**android:scaleType=“scaleXY”***.Shrestha很抱歉打扰您,但当我在imageView中将这一行
android:scaleType=“scaleXY”
放入时,他给了我无法解析的符号scaleXYOops忽略了这一点。请使用“FIT_XY”而不是“scaleXY”。添加此行android:adjustViewBounds=“true”