在android中如何在gridview中引入网格线

2024-01-20

经过大量搜索后,我能够找到我的问题的解决方案,在 Android 中如何

我可以使网格线在我的 gridview 中可见吗...因为它看起来很简单,但我仍然无法解决

这个问题确实提出了一些有用的建议,使网格线或边框在

网格视图.....

GridView 上的网格线 https://stackoverflow.com/questions/6010311/grid-lines-on-a-gridview

遵循这个问题建议的答案,但不知道如何创建 gridview 的子类并覆盖其方法,..? 建议解决方案


如果您需要更简单的解决方案,您可以在为每个网格项绘制的自定义视图中添加要绘制的边框。

示例代码:

public class ExampleAdapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    public ExampleAdapter(Activity activity)
    {
        this.activity = activity;
        this.inflater = activity.getLayoutInflater();
    }

    @Override
    public View getView(int pos, View convertView, ViewgGroup parent) {
        ViewHolder holder = null;
        if(converView == null) {
            convertView = inflater.inflate(R.layout.view_example);      
            holder = new ViewHolder();
            //Set holder ids here
            holder.title = convertView.findViewById(R.id.title)
        }
        //Populate your holder here with data here.
        holder.title.setText("My Awesome Title!");
        convertView.setTag(holder);
        return convertView;
    } 
}

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/grid_item_width"
    android:layout_height="@dimen/grid_item_height"
    android:background="@color/grid_border"
    android:padding="1dip" >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" >
        <TextView android:id="@+id/title" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
    </FrameLayout>
</FrameLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在android中如何在gridview中引入网格线 的相关文章

随机推荐