九宫格(大滑稽)

滑稽在这里向您拜年了~

九宫格的图是随便截的,九张图为什么都一样?

因为好弄呀(手动滑稽)

界面大概都是一样的吧

////

<GridView android:id="@+id/gridview"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:horizontalSpacing="10dp"

android:layout_gravity="center"

android:numColumns="3"

android:verticalSpacing="5dp"

android:stretchMode="columnWidth">

</GridView>

////

然后还有图片,记得要把正确的名称输入,是纯英文的哦

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_gridview, container, false);
List<ClassInfo> datas = new ArrayList<>();
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
datas.add(new ClassInfo(R.drawable.shadiao));
final CustomGridViewAdapter adapter = new CustomGridViewAdapter(getActivity(),datas);

GridView gridView = (GridView)view.findViewById(R.id.grid_view);
gridView.setAdapter(adapter);


return view;

}
}


public class MainActivity extends AppCompatActivity {
private GridViewFragment gridViewFragment;
private FragmentTransaction transaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager manager = getFragmentManager();
transaction = manager.beginTransaction();
if (gridViewFragment == null) {
gridViewFragment = new GridViewFragment();
transaction.add(R.id.show ,gridViewFragment);
}
transaction.replace(R.id.show, gridViewFragment);
transaction.commit();
}
}
最后代码的实现
视乎有点简单
那就先这样吧
谢谢诸位大佬
滑稽致敬

 

posted @ 2017-05-08 17:23  要加伟哥  阅读(516)  评论(0编辑  收藏  举报