在我的应用程序中,我必须根据用户交互动态更改 gridview 分隔符(例如,水平分隔符为红色,1px 为;垂直分隔符为蓝色,2px 为...)我该怎么做?
我试过这种方法 Android GridView with Separator ,但这对我不利,因为我需要不同颜色的线性和垂直分隔符。
我也看到了这个例子Android GridView draw dividers ,但我不知道如何以编程方式进行(没有 xml 文件)。
有什么帮助吗?
最佳答案
试试这个:
GridView grid = (GridView) findViewById(R.id.grid);
ArrayAdapter<String> a = new ArrayAdapter<String>(this, R.layout.item);
a.add("0"); a.add("1"); a.add("2");
a.add("3"); a.add("4"); a.add("5");
a.add("6"); a.add("7"); a.add("8");
a.add("9");
grid.setAdapter(a);
item.xml 在哪里:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/iten"
android:textSize="30dip"
android:textStyle="bold"
android:paddingLeft="10dip"
/>
GridView 定义为:
<GridView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/grid"
android:numColumns="3"
android:background="@drawable/grid"
android:listSelector="@null"
/>
最重要的是两个drawable:item.9.png 和grid.9.png
item.9.png 是 here
grid.9.png 是 here
结果 GridView 如下所示
关于android - android中的动态gridview分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16272067/