Android GridView图形边框
我已经挣扎了一段时间来划定边界。我想使用GridView制作一个滑动益智游戏,其中图像被分割成正方形并混合。首先,我用String ArrayAdapter设置了一个GridView,以查看它的外观 应该是这样的。我只是想知道如何制作这个有边框的框架Android GridView图形边框,android,Android,我已经挣扎了一段时间来划定边界。我想使用GridView制作一个滑动益智游戏,其中图像被分割成正方形并混合。首先,我用String ArrayAdapter设置了一个GridView,以查看它的外观 应该是这样的。我只是想知道如何制作这个有边框的框架 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" and
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit">
</GridView>
</LinearLayout>
活动课内:
String[] words = {"example","example1","example2"};
GridView grid;
public void onCreate(Bundle bund){
super.onCreate(bund);
setContentView(R.layout.grid_layout);
grid = (GridView) findViewById(R.id.gridView1);
grid.setAdapter(new ArrayAdapter<String>(MyActivity.this, android.R.layout.simple_list_item_1, words));
//grid.setOnItemClickListener(this);
String[]words={“example”、“example1”、“example2”};
网格视图网格;
创建后的公共空间(Bundle bund){
超级创造(外滩);
setContentView(R.layout.grid_layout);
grid=(GridView)findViewById(R.id.gridView1);
setAdapter(新的ArrayAdapter(MyActivity.this,android.R.layout.simple_list_item_1,words));
//grid.setOnItemClickListener(this);
如果我运行这段代码,我会得到一个没有边界的GridView。我已经看过类似的问题,但我仍然不知道如何去做
编辑查看
编辑:似乎我需要创建resource colors.xml。通过遵循上面列出的教程,它可以工作。感谢您提供的帮助。您应该执行以下操作:
GridView gv = findViewById(R.id.my_grid_view);
gv.setBackgroundColor(Color.WHITE);
gv.setVerticalSpacing(1);
gv.setHorizontalSpacing(1);
请参阅:使用gridView是一种错误的方法,为什么不使用自定义视图呢?是的。当我尝试添加android:background=“@color/blue”时在GridView中,它说“没有与给定名称匹配的资源”,而不是使用android.R.layout.simple_list_item_1…创建您自己的自定义单元格布局并添加边框。谢谢。如果我将GridView的背景颜色设置为黑色,并使用自定义网格布局在顶部绘制文本视图或图像视图,那么它可能会工作。