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.
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?
Thanks in advance!!
Instead of editing your view properties in XML, you can do so from the Properties window (on the right side of the Layout Editor). This window is available only when the design editor is open, so be sure you've selected the Design tab at the bottom of the window.
A well-designed custom view is much like any other well-designed class. It encapsulates a specific set of functionality with an easy to use interface, it uses CPU and memory efficiently, and so on. In addition to being a well-designed class, though, a custom view should: Conform to Android standards.
Create a custom viewGo to View > Workbook Views > Custom Views > Add. In the Name box, type a name for the view. Tip: To make a view easier to identify, you can include the name of the active worksheet in the name of a view. Under Include in view, select the check boxes of the settings that you want to include.
The Layout Preview displays a representation of how your XML code will be displayed on the device. It also allows you to see the different configurations of your layout, such as how would it look like while in portrait or landscape, or how does that TextView look on multiple locales such as English, German or Greek.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With