带内边框的Android网格视图

带内边框的Android网格视图,android,android-gridview,android-calendar,Android,Android Gridview,Android Calendar,我正在尝试制作一个日历应用程序,我希望里面的每个单元格都有一个边框,就像它是一个表一样,但我不知道怎么做,这是填充网格视图的适配器 public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; TextView dayView; if (convertView == null) { LayoutInflater vi = (Layo

我正在尝试制作一个日历应用程序,我希望里面的每个单元格都有一个边框,就像它是一个表一样,但我不知道怎么做,这是填充网格视图的适配器

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    TextView dayView;
    if (convertView == null) {
        LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.calendar_item, null);
    }
    v.setLayoutParams(new GridView.LayoutParams((int) Math.ceil((parent.getWidth() / 7)), (int) Math.ceil((parent.getWidth() / 7))));
    dayView = (TextView) v.findViewById(R.id.date);
    dayView.setText(days[position].toString());
    dayView.setBackgroundColor(Color.CYAN);
    dayView.setPadding(10, 10, 10, 10);
    dayView.setTextColor(Color.WHITE);
    if (days[position].getMonth() - 1 != month.get(Calendar.MONTH) || days[position].getYear() != month.get(Calendar.YEAR)) {
        dayView.setTextColor(Color.rgb(154, 154, 154));
    } else {
        if (days[position].hasEvent()) {
            if (days[position].getIsSelected()) {
                v.setBackgroundColor(Color.RED);
            } else {
                dayView.setTextColor(Color.BLACK);
            }
        } else {
            if (days[position].getIsSelected()) {
                dayView.setTextColor(Color.WHITE);
            } else {
                dayView.setTextColor(Color.BLACK);
            }
        }
    }
    return v;
}
这是calendar_item.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_height="60dp"
    android:layout_margin="0dp"
    android:clickable="false"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="0dp" >

    <TextView
        android:id="@+id/date"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@android:color/background_light"
        android:clickable="false"
        android:gravity="center"
        android:textColor="@android:color/white" />

</LinearLayout>

这就是现在的样子

使用形状作为单元格项的背景(在您的示例中为线性布局):)

这里有一个例子

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <stroke android:width="2dp" android:color="#FFFFFFFF" />
     <gradient android:startColor="#DD000000" android:endColor="#DD2ECCFA" 
            android:angle="225"/> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 

并从textview中删除bg以查看结果


希望有帮助。

使用形状作为单元格项的背景(在您的示例中为线性布局):)

这里有一个例子

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <stroke android:width="2dp" android:color="#FFFFFFFF" />
     <gradient android:startColor="#DD000000" android:endColor="#DD2ECCFA" 
            android:angle="225"/> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 

并从textview中删除bg以查看结果


希望有帮助。

首先在
可绘制文件夹中创建一个名为“shape\u my\u border.xml”的文件
.xml
,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

<!-- Change to the color you want for the background -->
<solid android:color="@color/white" />

<stroke
    android:width="1dp"
    android:color="@color/grey_border" />
    <!-- Change to the color you want for the border -->
</shape>

希望这有帮助。

首先在
可绘制文件夹中创建一个名为“shape\u my\u border.xml”的文件
.xml
,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

<!-- Change to the color you want for the background -->
<solid android:color="@color/white" />

<stroke
    android:width="1dp"
    android:color="@color/grey_border" />
    <!-- Change to the color you want for the border -->
</shape>

希望这有帮助。

尝试将带有透明区域的自定义边框图像设置为网格项父布局。创建自定义形状,设置为布局背景(calendar\u item.xml)尝试将带有透明区域的自定义边框图像设置为网格项父布局。创建自定义形状,设置为布局背景(calendar\u item.xml)我在哪里生成这个xml?在drawable中尝试过,然后将其用作calendar_item.xml的背景,但没有发生任何问题您是否删除了电视背景?我在哪里制作此xml?在drawable中尝试,然后将其用作calendar_item.xml的背景,但没有发生任何问题您是否已删除电视背景?