Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.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
Java 在Android中使用毕加索图像创建GridView_Java_Android_Picasa - Fatal编程技术网

Java 在Android中使用毕加索图像创建GridView

Java 在Android中使用毕加索图像创建GridView,java,android,picasa,Java,Android,Picasa,我正在尝试使用毕加索库创建带有图像的gridview。我正在使用gridview创建片段,并将适配器设置为gridview,但无法看到显示的任何内容。 以下是我的适配器代码: public class GridViewAdapter extends ArrayAdapter { private Context context; private LayoutInflater inflater; private String[] imageUrls; public

我正在尝试使用毕加索库创建带有图像的gridview。我正在使用gridview创建片段,并将适配器设置为gridview,但无法看到显示的任何内容。 以下是我的适配器代码:

public class GridViewAdapter extends ArrayAdapter {
    private Context context;
    private LayoutInflater inflater;

    private String[] imageUrls;

    public GridViewAdapter(Context context, String[] imageUrls) {
        super(context, R.layout.grid_item, imageUrls);

        this.context = context;
        this.imageUrls = imageUrls;

        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.grid_item, parent, false);
        }

        Picasso
                .with(context)
                .load(imageUrls[position])
                .fit() // will explain later
                .into((ImageView) convertView);

        return convertView;
    }
}
这是我片段的代码

public class ViewMoviesFragment extends Fragment {

    GridViewAdapter adapter;
    public ViewMoviesFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
          String[] eatFoodyImages = {
                "http://i.imgur.com/rFLNqWI.jpg",
                "http://i.imgur.com/C9pBVt7.jpg",
                "http://i.imgur.com/rT5vXE1.jpg",
                "http://i.imgur.com/aIy5R2k.jpg",
                "http://i.imgur.com/MoJs9pT.jpg",
                "http://i.imgur.com/S963yEM.jpg",
                "http://i.imgur.com/rLR2cyc.jpg",
                "http://i.imgur.com/SEPdUIx.jpg",
                "http://i.imgur.com/aC9OjaM.jpg",
                "http://i.imgur.com/76Jfv9b.jpg",
                "http://i.imgur.com/fUX7EIB.jpg",
                "http://i.imgur.com/syELajx.jpg",
                "http://i.imgur.com/COzBnru.jpg",
                "http://i.imgur.com/Z3QjilA.jpg",
        };
        View v= inflater.inflate(R.layout.grid_fragment, container, false);
        GridView gridview = (GridView) v.findViewById(R.id.poster_view);
        gridview.setAdapter(new GridViewAdapter(getActivity(), eatFoodyImages));



        return v;
    }
}
我的活动代码:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);

        if (fragment == null) {
            fragment = new ViewMoviesFragment();
            fm.beginTransaction()
                    .add(R.id.fragment_container, fragment)
                    .commit();
        }
    }
}
main_activity.xml

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</FrameLayout>

grid_item.xml

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</FrameLayout>

grid_fragment.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/poster_view"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:numColumns="2">
    </GridView>

</FrameLayout>


当我运行我的应用程序时,我得到的只是一个白色的窗口。AndroidManifest.xml具有internet访问权限。有人能帮我在gridview中显示图像吗?

问题出在您的GridViewAdapter中

    Picasso
            .with(context)
            .load(imageUrls[position])
            .fit() // will explain later
            .into((ImageView) convertView);

convertView
是一个框架布局

问题出在GridViewAdapter中

    Picasso
            .with(context)
            .load(imageUrls[position])
            .fit() // will explain later
            .into((ImageView) convertView);

convertView
是一个框架布局

@g2o你确定OP说的是
picasso
而不是google
picasa
?@LJ在代码中是picasso.with(context),所以我猜那是毕加索library@g2o你确定OP说的是毕加索而不是谷歌的毕加索吗?代码中的@LJ是毕加索。有(上下文),所以我知道那是毕加索的图书馆我删除了fit()现在可以工作了,但现在我仍然无法知道没有fit我的图像如何调整大小我删除了fit()现在可以工作了,但是现在我仍然不知道如何在不合适的情况下调整图像的大小