Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android studio layout editor shows custom view properties?

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?

Custom View

Properties panel not showing custom view properties

Thanks in advance!!

like image 631
tarekgreens Avatar asked Jun 26 '15 11:06

tarekgreens


People also ask

How can I see properties in Android Studio?

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.

What is custom view in Android Studio?

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.

Can you create custom views How?

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.

What does layout preview provide?

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.


1 Answers

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.

like image 195
Steffen Timm Avatar answered Oct 26 '22 03:10

Steffen Timm