我正在关注This Tutorial但是在尝试复制甚至编写与header_gradient.xml相同的代码时
header_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#24b2eb"
android:centerColor="#4ccbff"
android:endColor="#24b2eb"
android:angle="270"/>
<corners android:radius="5dp" />
</shape>
在空白的xml文件中显示错误,android studio支持创建空白的xml文件吗?或者有没有其他方法可以做到这一点?
答案 0 :(得分:1)
@tgrll感谢您回答我的问题,我的代码是正确的但是小版本只需要添加--android:layout_width =“50”android:layout_height =“50” - 代码中。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:layout_width="50" android:layout_height="50">
<gradient
android:startColor="#24b2eb"
android:centerColor="#4ccbff"
android:endColor="#24b2eb"
android:angle="270"/>
<corners android:radius="5dp" />
</shape>
答案 1 :(得分:0)
此示例代码可以帮助您。 注意android:shape =“rectangle”。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="180"
android:centerColor="@color/Bisque"
android:endColor="@color/Red"
android:startColor="@color/Red" />
<stroke
android:width="1dip"
android:color="@color/Black" />
<corners android:radius="3dip" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
请尝试使用此代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#24b2eb"
android:centerColor="#4ccbff"
android:endColor="#24b2eb"
android:angle="270"/>
<corners android:radius="5dp" />
</shape>