我正在开发的Android应用程序的主要活动已经变得非常大.这主要是因为它包含TabWidget3个选项卡.每个选项卡都有很多组件.活动必须立即控制所有这些组件.所以我认为你可以想象这个Activity有20个字段(几乎每个组件都有一个字段).它还包含许多逻辑(单击侦听器,填充列表的逻辑等).
我通常在基于组件的框架中做的是将所有内容拆分为自定义组件.然后,每个自定义组件都有明确的责任.它将包含它自己的一组组件以及与该组件相关的所有其他逻辑.
我试图弄清楚如何做到这一点,我在Android文档中发现了他们喜欢称之为"复合控制"的东西.(请参阅http://developer.android.com/guide/topics/ui/custom-components.html#compound并滚动到"复合控件"部分)我想基于XML文件创建这样一个组件来定义查看结构.
在文档中它说:
请注意,就像使用Activity一样,您可以使用声明式(基于XML)方法来创建包含的组件,也可以从代码中以编程方式嵌套它们.
嗯,这是个好消息!基于XML的方法正是我想要的!但它没有说明如何做到这一点,除了它"像一个活动"...但我在一个活动中做的是调用setContentView(...)从XML膨胀视图.如果您是子类,那么该方法不可用LinearLayout.
所以我尝试像这样手动扩充XML:
public class MyCompoundComponent extends LinearLayout {
public MyCompoundComponent(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_layout, this);
}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,除了我正在加载的XML已LinearLayout声明为根元素的事实.这导致被夸大LinearLayout的孩子MyCompoundComponent本身已经是一个LinearLayout!! 所以现在我们之间有一个冗余的LinearLayout MyCompoundComponent和它实际需要的视图.
有人可以请给我一个更好的方法来解决这个问题,避免LinearLayout实例化冗余吗?
我最近开始使用带有Facelets的JSF 2.0,并且对于了解<ui:include>Facelets 1.x提供的现有和其他模板技术的新复合组件感到困惑.
这些方法有什么区别?从功能上看,它们似乎提供了相同的:<ui:param>vs <cc:attribute>,<ui:insert>+ <ui:define>vs标记文件,重用现有模板.除了复合组件的语法和清晰的接口规范之外还有什么吗?性能会有所不同?
我有一个CompositeComponent(EditText + ImageButton)当点击按钮时,将清除edittext内容.它工作正常.我的问题是为我的组件设置属性.我使用declare-styleable来设置我的组件的属性.
我成功设置了minLines,maxLines和textColor.
如何通过xml将inputtype设置为我的组件.
我的attributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CET">
<attr name="MaxLines" format="integer"/>
<attr name="MinLines" format="integer"/>
<attr name="TextColor" format="color"/>
<attr name="InputType" format="integer" />
<attr name="Hint" format="string" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
并在main_layout.xml中使用mycomponent:
<com.test.ui.ClearableEditText
xmlns:cet="http://schemas.android.com/apk/res/com.test.ui"
android:id="@+id/clearableEditText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
cet:MaxLines="2"
cet:MinLines="1"
cet:TextColor="#0000FF"
cet:InputType="" <---I cant set this property--------->
cet:Hint="Clearable EditText Hint">
</com.test.ui.ClearableEditText>
Run Code Online (Sandbox Code Playgroud)
普通的Edittext用法:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberSigned" <--------I want to use this property--------> >
Run Code Online (Sandbox Code Playgroud)
我不能在我的attribute.xml中使用ENUM.怎么引用android:inputType="numberSigned"我的 cet:InputType?
编辑:
这就是我在ClearableEditText.java中分配属性的方法
TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CET,0, 0);
int minLines = a.getInt(R.styleable.CET_MinLines, 1); …Run Code Online (Sandbox Code Playgroud) 我正在创建一个自定义片段对话框,其圆角和布局不会填满屏幕宽度(我更喜欢它只是包装其内容).
这是我rounded_dialog.xml的drawable文件夹,由我的Custom调用,ThemeWithCorners作为对话框的背景.我还尝试将其设置为线性布局的背景,该布局创建其内容但没有任何作用.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="@android:color/white"/>
<corners android:radius="20dp"
/>
</shape>
Run Code Online (Sandbox Code Playgroud)
这就是我调用对话框的方式:
final String FTAG = "TAG_FRAGMENT_DIALOG_CALENDAR";
dialog = (CalendarDialog) fm.findFragmentByTag(FTAG);
ft = fm.beginTransaction();
if (dialog != null)
{
ft.remove(dialog);
}
dialog = CalendarDialog.newInstance(this);
dialog.setCancelable(true);
ft.add(dialog, FTAG);
ft.show(dialog);
ft.commit();
Run Code Online (Sandbox Code Playgroud)
在对话框的onCreate方法中我设置了样式和主题:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.ThemeWithCorners);
}
Run Code Online (Sandbox Code Playgroud)
这是onCreateView方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getDialog().setCanceledOnTouchOutside(true);
v = (MyCalendar)inflater.inflate(R.layout.calendar_dialog, container, true)
return v;
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将此添加到onCreateDialog方法,因为SO上的其他答案建议但不起作用:
@Override
public Dialog onCreateDialog(Bundle …Run Code Online (Sandbox Code Playgroud) 我一直在寻找,但找不到任何答案.我正在尝试实现的是类似于ICS gmail应用程序的撰写屏幕中的"To"字段的EditText.
这是描述我想要的图像:

我正在考虑扩展EditText和实现我自己的自定义EditText类,但我不确定如何做到这一点,即使这是最好的解决方案.有什么想法吗?
我正在尝试在Ember中构建一个简单的模态组件,但似乎Handlebars的"逻辑较少"对我来说太不合逻辑了.是否有任何理智的方式来实现这个结果?
<h2>Nice block about {{title}}</h2>
<a href="#" data-toggle="modal" id="add-item-{{title}}"> {{!this works}}
{{#my-modal modal-id="add-item-{{title}}" header='New {{title}}'}} {{! those don't}}
<p>My body blabla</p>
{{/my-modal}}
Run Code Online (Sandbox Code Playgroud)
目前我最终得到了我的模态id "add-item-{{title}}",字面意思,以及模态标题.
并且......不,现在我不打算将"标题"作为新的参数传递并在模态中使用它.另一个模板中的模态标题可能不是"新{{title}}",但"你确定吗?" 或"细节{{title}}".
当我在JSF中学习自定义组件开发时,我对组件系列,组件类型和渲染器类型之间的关系感到困惑.例如,我注册了一个渲染器和一个自定义组件,如下所示.
faces-config.xml:
<component>
<component-type>study.faces.Div</component-type>
<component-class>javax.faces.component.UIPanel</component-class>
</component>
<render-kit>
<render-kit-id>HTML_BASIC</render-kit-id>
<renderer>
<component-family>javax.faces.Panel</component-family>
<renderer-type>study.faces.DivRenderer</renderer-type>
<renderer-class>com.study.ui.DivRenderer</renderer-class>
</renderer>
</render-kit>
Run Code Online (Sandbox Code Playgroud)
我还在my.taglib.xml文件中注册了一个新标签,如下所示:
<tag>
<tag-name>div</tag-name>
<component>
<component-type>study.faces.Div</component-type>
<renderer-type>study.faces.DivRenderer</renderer-type>
</component>
</tag>
Run Code Online (Sandbox Code Playgroud)
这种配置非常有效.但是,我不明白为什么<component-family>javax.faces.Panel</component-family>在渲染器注册时需要该行.在my.taglib.xml,组件和渲染器是连接的,恕我直言,它应该足以为组件选择合适的渲染器.附加参数的用途是什么<component-family>?
我做了谷歌研究,我得到的所有答案都说"一个渲染器可以用来渲染多个组件.这些组件属于一个系列".但这些陈述并没有明确我的困惑.有人可以解释组件类型,组件系列和渲染器选择策略之间的关系吗?(希望有一个很好的例子.)
我有一个类似的课程
public class CountryVO {
private String countryCode;
private String countryName;
private Drawable countryFlag;
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public Drawable getCountryFlag() {
return countryFlag;
}
public void setCountryFlag(Drawable countryFlag) {
this.countryFlag = countryFlag;
}
}
Run Code Online (Sandbox Code Playgroud)
并希望将此类的对象存储在Android的TypeArray xml中
<resources>
<array name="custom_arr">
<item>
<countryName>Albania</countryName>
<countryCode>al</countryCode>
<countryFlag>@drawable/al</countryFlag>
</item>
<item>
<countryName>Algeria</countryName>
<countryCode>dz</countryCode>
<countryFlag>@drawable/dz</countryFlag>
</item>
<item>
<countryName>American …Run Code Online (Sandbox Code Playgroud) 我想要一个按钮作为进度条.
+
= ........
例如,随着任务的进行,填充绿色背景的按钮.
我知道我可以创造自己的,但如果有一些现成的东西,我很乐意使用它.
有没有人知道适合该法案的免费或商业组件?
我更喜欢它在Delphi-2007中工作,但如果它只在XE2中可用,那也没关系.
更新
TMS具有glassbutton允许透明度的.如果你将一个Shape(带圆角)放在深绿色的下面,它看起来就像我想要的效果.
只需增加形状的宽度以匹配进度,您就可以开展业务.
当我有时间的时候,我会制作一个填充颜色的按钮,并建立一个链接.
试图为一组TFrame-descendent组件重新安排我的包,我发现它似乎有必要将我的一些实用程序TFrame后代与使用它们的对话框形式分开,主要是因为前者在调色板中注册为true组件和IDE似乎有时会混淆IDE使用它们的对话框形式.反过来,对话框形式由非可视组件调用,这些组件是第三个包的一部分.这一点,到目前为止,似乎让大多数编译器的依赖性有关的投诉 /混乱走开.(但我还没出来).
当使用对话框窗体(调用框架)编译包时,我收到警告"单元'MyFrames'被隐式导入包'MyDialogForms'"
鉴于它显示为编译器警告,我很久以前就给人的印象是"隐式导入"一个单元通常不是一件好事.是否有特定情况并非如此?即隐含导入单位是否合适,和/或适当的做法?......如果是,那些具体案例是什么?