我正在使用gridvew作为布局来填充我的项目,圆形按钮,但是我在安装大网格时遇到了问题,11 x 11.当我使用更大的屏幕时,它适合但它会停止一半?这是因为我把我的roundbutton.xml中的szie?在
gridview布局
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView1"
android:numColumns="11"
android:gravity="center"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
item.xml
<?xml version="1.0" encoding="utf-8"?> <Button xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="O" android:id="@+id/grid_item_label" android:layout_column="1" android:background = "@drawable/roundedbutton"/>
roundedbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2sp" android:color="#fff" />
<size
android:width="5dp"
android:height="5dp"/>
</shape>
activity_main.java
gridView = (GridView) findViewById(R.id.gridView1);
customGridAdapter = new CustomGridViewAdapter(this, R.layout.button_item, gridArray);
gridView.setAdapter(customGridAdapter);
adapter.java
@Override
public View getView(final int position, View convertView, final ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
为此,您必须计算设备宽度和高度运行时间
int width = devicewidth/11 ; int height =deviceheight/11 ;
使用此参数,您必须传入GridView的适配器
android.widget.AbsListView.LayoutParams parms = new android.widget.AbsListView.LayoutParams(width , height);
调整其细胞大小.
