【发布时间】:2015-04-07 05:03:02
【问题描述】:
我在搜索具有良好图形的按钮时发现了这段代码,
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="100dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#7995A8"
android:startColor="#E8E8E8"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>
但是,当我将其复制并粘贴到 Android Studio 中的 XML 文件中时,它会显示并显示错误:
“元素形状没有必需的属性android:layout_height”
还有一个错误:
“元素形状没有必需的属性android:layout_width”
我尝试设置 android:layout_width="" 和 android:layout_heigth""
和android:layout_width"wrap_content",android:layout_heigth="wrap_content",错误消失了,但我无法设置任何按钮将它作为背景......所以我不能以这种方式使用这个XML。
我应该将它们设置为什么?
【问题讨论】: