我想写一个2048小游戏的安卓界面请给我布局代码
以下是一个简单的2048小游戏的安卓界面布局代码,你可以根据自己的需要进行修改:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/score_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score: 0"
android:textSize="20sp"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<GridLayout
android:id="@+id/grid_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/score_text_view"
android:rowCount="4"
android:columnCount="4"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:useDefaultMargins="true"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<TextView
android:id="@+id/textview00"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/tile_2"
android:gravity="center"
android:textSize="32sp"
android:textColor="@color/tile_text_color"
android:textStyle="bold"
android:text="2"
android:layout_margin="4dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<!-- Repeat for the rest of the tiles in the grid -->
</GridLayout>
<Button
android:id="@+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp" />
</RelativeLayout>
这个布局文件包含一个得分文本视图,一个4x4网格布局,以及一个重置按钮。你需要在drawable文件夹中添加一个名为tile_2.xml的形状,来为网格中的方块提供样式。你可以在这个文件中使用shape标签创建自定义形状,比如矩形或圆角矩形。
原文地址: http://www.cveoy.top/t/topic/bD94 著作权归作者所有。请勿转载和采集!