我正在为Android App创建一个自定义组件(恰好是音频混音器的音量推子)。它工作正常。
我想要的是在运行时加载此组件的多个实例。 我试过这个:
LinearLayout layout = (LinearLayout)findViewById(R.id.mixerContainer) //This layout
for(int i=0;i<8;i++){
LayoutInflater l = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = l.inflate(R.Layout.MyVolumeFader, null);
layout.add(v);
}
这会正确添加视图,但不会附加我的组件的所有逻辑(包含在MyVolumeFader类中)。
我该如何解决这个问题?
-
代码如下:
MyVolumeFader.java
public class MyVolumeFader extends RelativeLayout{
[...]
private VerticalSeekBar volumeBar;
[...]
->volumeBar handling<-
}
MyVolumeFader.xml
<RelativeLayout...
Some TextViews, Buttons and a VerticalSeekBar are here...
谢谢。
答案 0 :(得分:0)
你可以考虑使用windowmanager及其'addview方法来解决你的问题。
mWindowManager.addView(new ChartTools(this, a, list, "业务统计").getChart(),
ParamTools.getChartParams());