【问题标题】:Android rounded border color top-left only dinamicallyAndroid圆角边框颜色左上角仅动态
【发布时间】:2017-09-03 13:55:52
【问题描述】:

我需要动态设置一个 GridView 项目,我正在使用带有背景可绘制圆角的 LinearLayout,但我无法弄清楚像这张图片一样只设置左上角边框颜色....

<img src="https://i.stack.imgur.com/R8lyH.png"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/btn_rounded_white"
        android:orientation="vertical">

        <TextView
            android:id="@+id/gridview_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"
            android:text="@string/app_name"
            android:textSize="@dimen/gridview_text"
            android:textStyle="bold"
            android:layout_gravity="center"
            android:gravity="center">

        </TextView>

    </LinearLayout>


<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="@color/griditem_cat" />
    <padding android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"/>
    <corners android:bottomRightRadius="7dp"
        android:bottomLeftRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp"/>
</shape>

【问题讨论】:

  • 您想动态设置左上角颜色还是只有这四种颜色?
  • @Aditya Vyas-Lakhan 它需要用十六进制颜色动态着色,我正在尝试使用三角形自定义视图,但我丢失了像所附图像示例一样的圆形左上角
  • 如果是动态的,你需要在你的“三角形”drawable 上调用Drawable#setColorFilter
  • @pskink 我会尝试设置三角形颜色...
  • 正如我所说的使用三角形,我可以使用自定义视图 (imgur.com/a/3i2JB) 设置颜色,但我没有找到如何使其左上角圆形 ``

标签: android gridview layout rounded-corners border-layout


【解决方案1】:

grid_item.xml

<RelativeLayout 
android:id="@+id/gridview_item" 
android:layout_width="match_parent" 
android:layout_height="match_parent">
     <PinnedGridItemView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/>
    <TextView android:id="@+id/gridview_text">
     </TextView>
</RelativeLayout>

类别适配器

pin = (PinnedGridItemView) relativeLayout.findViewById(R.id.pinned_grid_item);
pin.setColorCode(Color.RED);// Here I set any color that I want dynamically, the problem now is to solve top-left rounded corner

【讨论】:

    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 2012-02-17
    • 2019-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 2017-05-27
    相关资源
    最近更新 更多