之前是用RelativeLayout相对布局来实现的批量按钮的排列显示,感觉不是太方便了现在。现在可以用GridView来实现批量按钮的排列问题。
效果图如下:
(向要圆形按钮的话,查看之前的博客即可。)
public class MainActivity extends AppCompatActivity { private Context mContext; private GridView gridView; private int btnCount = 52; private int btnEachRowCount = 6; private ArrayList<String> stringArrayList; private ButtonListAdapter buttonListAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = this; stringArrayList = new ArrayList<>(); DeviceBaseInfo.getActivityWidthAndHeight(getWindowManager()); gridView = findViewById(R.id.Main_gViewBtnList); for (int i=0;i<btnCount;i++) { stringArrayList.add(i + ""); } buttonListAdapter = new ButtonListAdapter(mContext, stringArrayList); gridView.setAdapter(buttonListAdapter); } }
我这边是随手写了一个适配器,其实不用写。直接用BaseAdapter即可。
主要是一个思路,其他代码就不写了。