今天的任务为创建photoGallery应用,代码如下:
PhotoGalleryActivity.java:
package com.example.a49840.photogallery;
import android.support.v4.app.Fragment;
public class PhotoGalleryActivity extends SingleFragmentActivity {
@Override
protected Fragment createFragment() {
return PhotoGalleryFragment.newInstance();
}
}
fragment_photo_gallery.xml:
<!--?xml version="1.0" encoding="utf-8"?-->
</android.support.v7.widget.recyclerview>
PhtotGalleryFragment.java:
package com.example.a49840.photogallery;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class PhotoGalleryFragment extends Fragment {
private RecyclerView mPhotoRecyclerView;
public static PhotoGalleryFragment newInstance() {
return new PhotoGalleryFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.<em>fragment_photo_gallery</em>, container, false);
mPhotoRecyclerView = (RecyclerView) v.findViewById(R.id.<em>photo_recycler_view</em>);
mPhotoRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3));
return v;
}
}
创建成功的界面如下:
)