如何使android xml像这张图片一样?

我很抱歉我的英语不好和编程技巧很差。我想在 Android Studio 上制作一个如下图所示的 .xml 文件。我想用很多复选框等来做到这一点。但我想对这些按钮进行垂直分组以使java中的代码更容易。你能给我一个如何构建代码的想法吗?


http://img1.mukewang.com/6141b7b10001488603620153.jpg

临摹微笑
浏览 229回答 3
3回答

牧羊人nacy

你应该使用表格布局,你可以从谷歌安卓文档中找到你在该页面上的所有内容

慕慕森

我认为实现此类视图的最佳方法是使用带有 GridLayoutManager 的 recyclerView,但是如果您想在 xml 中处理它,您可以使用带权重的 LinearLayouts。例如,此代码将生成一个 2x2 网格<LinearLayout android:orientation="vertical"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="30dp"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent">&nbsp; &nbsp; <LinearLayout android:orientation="horizontal"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent">&nbsp; &nbsp; &nbsp; &nbsp; <LinearLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight="1"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"/>&nbsp; &nbsp; &nbsp; &nbsp; <LinearLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight="1"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"/>&nbsp;</LinearLayout>&nbsp;<LinearLayout android:orientation="horizontal"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="30dp"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent">&nbsp; &nbsp; &nbsp; &nbsp; <LinearLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight="1"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"/>&nbsp; &nbsp; &nbsp; &nbsp; <LinearLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight="1"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"/>&nbsp; &nbsp;</LinearLayout></LinearLayout>

慕尼黑5688855

您应该使用 GridLayout 来创建您所说的布局。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java