Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind android custom view to a specific layout xml (is this even possible?)

I'd like to put a custom view multiple times in my main.xml which consists of a RelativeLayout, some controls and then my custom view. This custom view should use the following (simplified) xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="220px"
android:layout_height="220px"
android:background="@drawable/contextitemshape">
<TextView
    android:text="some caption"
    android:textSize="23px"
    android:textColor="#000000"/>
    <FrameLayout
    android:id="@+id/content"/>
</RelativeLayout>

How can I get it to use this file each time it is created? Is that even possible in android? All the custom views I can find don't use an own layout-xml file.

Thank you!

like image 582
ShadowMare Avatar asked Jan 17 '11 12:01

ShadowMare


1 Answers

Have your custom View inflate the layout as part of its setup. Here is a project that, among other things, implements a ColorMixer custom View that inflates a layout containing three SeekBar widgets and some other stuff.

like image 184
CommonsWare Avatar answered Sep 29 '22 04:09

CommonsWare