如何给单线边框gridview的机器人 [英] How to give single line border to gridview android

查看:163
本文介绍了如何给单线边框gridview的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的GridView客户适配器。为了给每个单元格边框,我已经把他们安置在两个布局。第一个布局有黑色BG和第二布局有白色BG和内容。我已经给家长布置1DP填充,这赋予了边框的外观

但问题是,当两个小区满足垂直,其边框尺寸变2DP即一个单元格的下边框合并到其他细胞的上边框。

不过,我喜欢创造的边界在给定的图像

下面是$ C $我当前单元格的xml文件了C

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / layBorder
    机器人:layout_width =77dp
    机器人:layout_height =WRAP_CONTENT
    机器人:后台=#000000
    机器人:方向=垂直
    机器人:填充=1DP>

    <的FrameLayout
        机器人:ID =@ + ID / FrameLayout1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:后台=#FFFFFF>

        < ImageView的
            机器人:ID =@ + ID / ivElementName
            机器人:layout_width =40dp
            机器人:layout_height =60dp
            机器人:layout_gravity =center_vertical | center_horizo​​ntal
            机器人:layout_margin =1DP
            机器人:adjustViewBounds =真
            机器人:后台=#00000000
            机器人:=了maxHeight60dp
            机器人:=了maxWidth40dp
            机器人:=了minHeight60dp
            机器人:=了minWidth40dp/>

        < ImageView的
            机器人:ID =@ + ID / ivElementImg
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_gravity =底部| center_vertical | center_horizo​​ntal
            机器人:layout_marginLeft =1DP
            机器人:layout_marginRight =1DP
            机器人:adjustViewBounds =真
            机器人:后台=#00000000
            机器人:baselineAlignBottom =真
            机器人:cropToPadding =真
            机器人:=了maxHeight30dp
            机器人:=了maxWidth30dp
            机器人:=了minHeight30dp
            机器人:=了minWidth30dp
            机器人:能见度=隐形/>

    < /的FrameLayout>

< / LinearLayout中>
 

解决方案

您应该做下:

  • 您的GridView的设置背景颜色也将是一个边框颜色
  • 您的网格项的设置背景颜色,因为你需要
  • 设置纵向和横向间距这将是一个边框厚度

和不要忘记改变你的网格项目布局的高度,match_parent

  GridView的GV = findViewById(R.id.my_grid_view);
gv.setBackgroundColor(Color.WHITE);
gv.setVerticalSpacing(1);
gv.setHorizo​​ntalSpacing(1);
 

I have created gridview with customer adapter. To give each cell border, I have placed them in two layouts. The first layout has black bg and second layout has white bg and contents. and I have given the parent layout 1dp padding, which given a border look

but the problem is that when two cells meet vertically, their border size becomes 2dp i.e. one cell's bottom border merges into other cell's top border.

But I like to create border as in given image

Here is code of my current cell's xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layBorder"
    android:layout_width="77dp"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="vertical"
    android:padding="1dp" >

    <FrameLayout
        android:id="@+id/FrameLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF" >

        <ImageView
            android:id="@+id/ivElementName"
            android:layout_width="40dp"
            android:layout_height="60dp"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_margin="1dp"
            android:adjustViewBounds="true"
            android:background="#00000000"
            android:maxHeight="60dp"
            android:maxWidth="40dp"
            android:minHeight="60dp"
            android:minWidth="40dp" />

        <ImageView
            android:id="@+id/ivElementImg"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="bottom|center_vertical|center_horizontal"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"
            android:adjustViewBounds="true"
            android:background="#00000000"
            android:baselineAlignBottom="true"
            android:cropToPadding="true"
            android:maxHeight="30dp"
            android:maxWidth="30dp"
            android:minHeight="30dp"
            android:minWidth="30dp"
            android:visibility="invisible" />

    </FrameLayout>

</LinearLayout>

解决方案

You should do the next:

  • set background color of your gridview it will be a border color
  • set background color of your grid item as you need
  • set vertical and horizontal spacing it will be a border thickness

And don't forget to change you grid item layout height as match_parent

GridView gv = findViewById(R.id.my_grid_view);
gv.setBackgroundColor(Color.WHITE);
gv.setVerticalSpacing(1);
gv.setHorizontalSpacing(1);

这篇关于如何给单线边框gridview的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆