New*_*e23 12 java android android-custom-view
我有一个复合视图,包含两个按钮和一个文本视图.我想在Android Studio布局编辑器中编辑这些子视图的属性,但我不能.它仅显示基本属性,但不显示自定义视图的属性.
Android Studio布局编辑器是否仅显示默认设置的有限数量的属性?是否可以从那里编辑我的自定义视图的属性,而无需手动编辑XML文件?


提前致谢!!
小智 2
如http://developer.android.com/training/custom-views/create-view.html#customattr中所述,您必须添加新的资源 (res/values/attrs.xml)。
<resources>
<declare-styleable name="PieChart">
<attr name="showText" format="boolean" />
<attr name="labelPosition" format="enum">
<enum name="left" value="0"/>
<enum name="right" value="1"/>
</attr>
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
在您的视图中,您必须引用这个新资源
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customviews">
<com.example.customviews.charting.PieChart
custom:showText="true"
custom:labelPosition="left" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在您应该在编辑器中看到属性。
| 归档时间: |
|
| 查看次数: |
5197 次 |
| 最近记录: |