九宫格

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了九宫格相关的知识,希望对你有一定的参考价值。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.yz.jiugongge.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/yz"
android:orientation="horizontal">


</LinearLayout>

</LinearLayout>


GrideView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
tools:context="com.example.yz.jiugongge.MainActivity">

<GridView
android:layout_width="match_parent"
android:numColumns="3"
android:layout_height="match_parent"
android:id="@+id/view"
>
</GridView>
</LinearLayout>


SimpleAdapter

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


<ImageView
android:layout_width="100dp"
android:layout_height="150dp"
android:id="@+id/image"
/>

</LinearLayout>




技术分享

 


MainActivity


package com.example.yz.jiugongge;

import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction fragmentTransaction =getFragmentManager().beginTransaction();
Activity gridFragment =new Activity();
fragmentTransaction.add(R.id.yz,gridFragment);
fragmentTransaction.commit();
}
}


Activity


package com.example.yz.jiugongge;

import android.app.Fragment;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Activity extends Fragment {
private SimpleAdapter adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.gridview, container, false);
adapter=new SimpleAdapter(getActivity(),getData(),R.layout.simpleadapter,
new String[]{"img"},
new int[]{R.id.image}
);
GridView gridView= (GridView)view.findViewById(R.id.view);
gridView.setAdapter(adapter);
return view;
}
private List<HashMap<String, Object>> getData(){
List<HashMap<String,Object>>datas = new ArrayList<>();
HashMap<String,Object> data = new HashMap<>();
//Map映射添加数据
data.put("img",R.mipmap.ic_launcher);
//将Map放到list
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
//将Map放到list
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
data = new HashMap<>();
data.put("img",R.mipmap.ic_launcher);
datas.add( data);
return datas;
}

}










































































































































































以上是关于九宫格的主要内容,如果未能解决你的问题,请参考以下文章

人才盘点九宫格你还不来学一学人才九宫格,知道领导在做人才梯度结构盘点时把你划分为属于哪一类人才吗?

抖音九宫格直播是啥意思

九宫格改进

九宫格数独游戏每行每列每条对角线之和都相等如何填数?

哪位大虾有九宫格(数独9*9)的C语言详细代码!!!!!!!!!!!!!!!!!!菜鸟在等候!!!!!

九宫格的实现