Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android GridView使项目适合每个屏幕尺寸大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用gridvew作为布局来填充我的项目,圆形按钮,但是我在安装大网格时遇到了问题,11 x 11.当我使用更大的屏幕时,它适合但它会停止一半?这是因为我把我的roundbutton.xml中的szie?在我的手机较小的屏幕上,它确实适合并延伸到屏幕末端的末端.我需要适合屏幕,无论大小为11 x 11?

gridview布局

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://scheR_273_11845@as.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://scheR_273_11845@as.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://scheR_273_11845@as.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);

调整其细胞大小.

大佬总结

以上是大佬教程为你收集整理的Android GridView使项目适合每个屏幕尺寸全部内容,希望文章能够帮你解决Android GridView使项目适合每个屏幕尺寸所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。