安卓:圆角的TextView XML布局与自定义页眉页眉、自定义、布局、圆角

2023-09-06 09:36:43 作者:帅癌晚期

我想创造我的TextView定制XML布局,使用圆角和一个自定义标题,如这个例子。

I would like to create a custom XML layout for my TextView, using rounded corners and a custom header, such as this example.

我发现,这非常有用的链接创建以下颇为相似的结果。

I found this very useful link that creates the following quite similar result.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Bottom 2dp Shadow -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#d8d8d8" />
            <corners android:radius="7dp" />
        </shape>
    </item>

    <!-- White Top color -->
    <item android:bottom="3px">
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="7dp" />
        </shape>
    </item>
</layer-list>

不知是否不可能性来修改上面的XML布局,以获得标题添加好友的风格,即较暗的灰色背景和头部的TextView之间的分隔(添加好友)和以下的TextView(一个包含昵称或电子邮件和搜索按钮)。

I wonder if it possibile to modify the XML layout above to get the header "ADD FRIEND" style, that is the darker gray background and the divider between the header textview ("ADD FRIEND") and the textview below (the one containing the "Nickname or email" and the "search" button).

我想它可能是更容易使用的图像/绘背景做,但得到它在XML做将是真棒(以可重用性,例如计算)。

I am thinking it is probably easier to do it with an image/drawable background, but getting it done in XML would be awesome (in terms of reusability for example).

如何进行任何帮助或建议,非常欢迎!

Any help or suggestion on how to proceed is very welcome!

推荐答案

如果你不使用图像的话需要绘制三个XML和创建这种类型的布局:1 linearlayout_background.xml

if you not using image for that then require three xml in drawable and create this type of layout : 1 linearlayout_background.xml

<?xml version="1.0" encoding="utf-8"?>

<item>
    <shape android:shape="rectangle" >
        <solid android:color="#CABBBBBB" />

        <corners android:radius="2dp" />
    </shape>
</item>
<item
    android:bottom="2dp"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp">
    <shape android:shape="rectangle" >
        <solid android:color="@android:color/white" />

        <corners android:radius="2dp" />
    </shape>
</item>

header_background:

header_background :

        

    <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />

    <solid android:color="@color/off_black1" />
</shape></item>

buttonbackground

buttonbackground

        

    <corners android:radius="5dp" />

    <solid android:color="#00000000" />

    <stroke android:width="1dp" android:color="@color/off_white2" />
</shape></item>