请问Android的工作室布局编辑器显示自定义视图属性? [英] Does Android studio layout editor shows custom view properties?

查看:515
本文介绍了请问Android的工作室布局编辑器显示自定义视图属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由两个按钮和一个文本视图的复合视图。我想编辑的在Android Studio的布局编辑器,这些子视图属性,但我不能。这只能说明基本属性,但没有我的自定义视图属性。

I have a compound view which consists of two Buttons and one Text view. I want to edit properties of these child views in the Android Studio Layout Editor but I can't. It only shows basic properties but no properties of my custom view.

请问Android的工作室布局编辑器只显示默认设置的属性数量有限?是否有可能从那里修改我的自定义视图的属性,而无需手动编辑XML文件?

Does the Android Studio Layout Editor only shows limited number of properties set by default? Is it possible to edit properties of my custom view from there, without manually editing the XML files?

在此先感谢!

推荐答案

作为的 http://developer.android.com/training/custom-views/create-view.html#customattr 必须添加一个新的ressource(RES /价值/ attrs.xml)。

As described in http://developer.android.com/training/custom-views/create-view.html#customattr you have to add a new ressource (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>

在您查看你必须引用这个新的ressource

Within your View you have to reference this new ressource

<?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>

现在你应该看到的属性编辑器。

Now you should see the properties in the editor.

这篇关于请问Android的工作室布局编辑器显示自定义视图属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆