In android how to bring gridlines in gridview

佐手、 提交于 2019-12-12 15:42:32

问题


After searching out a lot i could able to find the solution of my problem that in Android how

can i make gridlines visible in my gridview....as it seems simple but i still couldn't resolve

the problem do suggest some useful suggestion to make gridlines or borders visible on

gridview.....

Grid-lines on a GridView

followed the answer suggested for this question but don't know how to create subclass of gridview and override its methods,,..?? suggest solution


回答1:


If you need a simpler solution, you could add the border to be drawn in your custom views drawn for each grid item.

Example code:

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>


来源:https://stackoverflow.com/questions/12305755/in-android-how-to-bring-gridlines-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!