Android 包含可绘制xml文件时出错
社区你好,Android 包含可绘制xml文件时出错,android,xml,eclipse,Android,Xml,Eclipse,社区你好, 我想将不同的可绘制xml文件保存到我的activity_main.xml中 但是,当我想包含以下代码时: <?xml version="1.0" encoding="utf-8" ?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <size android:la
我想将不同的可绘制xml文件保存到我的activity_main.xml中
但是,当我想包含以下代码时:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<size
android:layout_height="110dp" />
</shape>
</item>
</selector>
名称为button_height.xml,保存到我的主文件中:
<Button
android:id="@+id/cmda1"
android:layout_width="110dp"
android:layout_height="@drawable/button_height" />
它不起作用,Eclipse只说:
必须提供布局高度属性。
和XML文件中出错:中止生成 我在网上搜索了一个答案,但没有找到。 但我认为很多人都犯了一个简单的错误 所以,我希望得到有用的答案
对不起,我的英语糟透了。你对可绘图、选择器和尺寸的整个想法都搞砸了。不能在选择器中输入高度,也不能将选择器(可绘制)作为高度 这样做 如果要使用xml获取高度 在res文件夹中添加一个名为res/values/dimens.xml的文件,并在该文件夹中添加此行
<resources>
<integer name="btn_cmda_height" >110dp</integer>
</resources>
通过创建包含不同值的文件,使其动态适应各种屏幕大小。虽然这是老办法
阅读更多有关新方法的信息
如果不想使用xml获取高度
只需在按钮cmda1
height属性中执行以下操作
注意:
您的选择器代码错误,根本不需要。选择器用于定义视图的背景状态。@drawable/button\u如果高度为可绘制类型,则必须像在layout\u Width中一样传入类似于“110dp”的字符串。感谢您的快速回答,但我知道如何将其直接写入xml文件。但是,对于不同的显示维度,您的解决方案是动态的吗?
android:layout_height="@dimen/btn_cmda_height"
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-xlarge/dimens.xml