Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 具有不同列大小的GridView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试创建一个可滚动的高分列表,如下所示:
foo         1000
bar         876
foobar      500
foobarfoo   1

我目前正在使用GridView.我想将名称列宽设置为屏幕的60%,将得分列宽度设置为40%.可能吗?

目前我正在通过costuR_913_11845@适配器尝试.这是getview功能

public View getView(int position,View convertView,ViewGroup parent) {
    TextView tv;
    if (convertView == null) {
        tv = new TextView(context);
        tv.setTextSize(25);
        tv.setTextColor(Color.WHITE);              

        if (position % 2 == 0)
        {
            tv.setLayoutParams(new GridView.LayoutParams((width/10)*6,50));
        }
        else
        {
            tv.setLayoutParams(new GridView.LayoutParams((width/10)*4,50));
        }
    }
    else {
        tv = (TextView) convertView;
    }

    tv.setText(texts[position]);
    return tv;
}

布局由gridview和底部的按钮构建. XML文件是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://scheR_913_11845@as.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/top">
    <GridView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="2"
              android:id="@+id/grid"
              android:numcolumns="2"
              android:columnWidth="0dp"
              >
    </GridView>
    <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/BACkbutton" android:text="@String/BACkstr"></Button>

</LinearLayout>

所以问题再次出现:是否可以设置GridView以添加不同大小的列?如果是,那我的方法是好的? (可能不是,因为它不起作用:))我只是错过了什么?

先感谢您!

解决方法

@H_404_21@ 我们不得不为一个项目做这个,并且不想使用除GridView以外的任何东西,因为功能被重复,但在一个GridView上我们需要一个稍微不同的视图配置(但仍然使用适配器和所有其他好东西).我们发现如果你覆盖GridView的layoutChildren函数,你可以这样做,然它的文档记录很差.

我们的实现检查特殊视图以及是否已实现新布局:

@Override
protected void layoutChildren(){
    super.layoutChildren();
    if(!isSpecial || layoutAlreadySet) return;
    layoutAlreadySet = true;
    //Implement special layout....
}

大佬总结

以上是大佬教程为你收集整理的android – 具有不同列大小的GridView全部内容,希望文章能够帮你解决android – 具有不同列大小的GridView所遇到的程序开发问题。

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

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