九九九九九宫格
这次的作业为九宫格 ,首先依旧是最基本的布局
<RelativeLayout
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"
tools:context="com.example.lenovo.girdview.MainActivity">
<GridView
android:id="@+id/gv"
android:numColumns="3"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
之后再是一个item布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你好"
android:textSize="50sp"
android:layout_gravity="center"/>
</LinearLayout>
然后就是java
public class MainActivity extends AppCompatActivity
{
private GridView gridView;
private MyAdapter myAdapter;
private List<String> list;
private String[] s1 = new String[] { "1111", "2222", "3333", "4444", "5555", "6666", "7777", "8888" , "9999"};