Android的边框底部,自定义视图不工作 [英] Android border bottom for custom view not working

查看:286
本文介绍了Android的边框底部,自定义视图不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的是有上有一个梯度和灰色的底边框一个RelativeLayout的,我用我的应用程序下面的自定义视图:

What I'm trying to do is to have a relativelayout with a gradient on it and a gray bottom border, I'm using the below custom view in my application:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageView 
    android:id="@+id/list_item_image"
    android:layout_width="match_parent"
    android:layout_height="@dimen/SIZE_LIST_ITEM_LARGE"
    android:scaleType="centerCrop"/>

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/shape_list_item_gradient" />

<com.rahil.widgets.CustomTextView 
    android:id="@+id/list_item_title"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:gravity="bottom"

    android:textColor="@color/COLOR_BLACK"/>

</RelativeLayout>

这是shape_list_item_gradient:

and this is shape_list_item_gradient:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <gradient
            android:startColor="#FFFFFFFF"
            android:endColor="#00FFFFFF"
            android:angle="90" />
    </shape>
</item>
<item android:bottom="2dp">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@color/COLOR_GRAY" />
    </shape>
</item> 
</layer-list>

但上面code适用边框所有边框不只是底部边框。我添加了单独的形状XML到RelativeLayout的,但我以为有梯度的看法覆盖它,也许它没有工作?我很安静丢失。感谢您的帮助。

but the above code applies border to all borders not just bottom border. I added the separate shape xml to the relativelayout but it didn't work which I assume the view with gradient covers it maybe?? I'm quiet lost. thanks for your help.

推荐答案

的android:底部属性实际上是底部的像素偏移所指出的这里图层列表可绘制。还有就是要创建一个仅在一侧抚摸矩形没有明确的办法。

The android:bottom attribute is actually the "bottom offset in pixels" as noted here about layer-list drawables. There is no explicit way to create a rectangle that is stroked only on one side.

不过,你可以使用同样的伎俩Krylez 这里建议:<一href=\"http://stackoverflow.com/a/19239478/1538674\">http://stackoverflow.com/a/19239478/1538674

However you can use the same trick that Krylez suggested here: http://stackoverflow.com/a/19239478/1538674

因此​​,像这样:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#FFFFFFFF"
                android:endColor="#00FFFFFF"
                android:angle="90" />
        </shape>
    </item>
    <item android:top="-3dp" android:right="-3dp" android:left="-3dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="2dp" android:color="@color/COLOR_GRAY" />
        </shape>
    </item>
</layer-list>

这篇关于Android的边框底部,自定义视图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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