且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建自定义视图通过充气的布局?

更新时间:2021-08-23 08:55:15

是的,你可以做到这一点。 RelativeLayout的,LinearLayout中,等有意见,自定义布局是一个自定义视图。只是要考虑的,因为如果你想创建一个自定义布局,你可以。

Yes you can do this. RelativeLayout, LinearLayout, etc are Views so a custom layout is a custom view. Just something to consider because if you wanted to create a custom layout you could.

您想要做的是创建一个复合控制。您将创建RelativeLayout的子类,在code(TextView的,等等)加入我们的所有的组件,并在构造函数你可以阅读从XML传入的属性。然后,您可以通过该属性为您的标题TextView的。

What you want to do is create a Compound Control. You'll create a subclass of RelativeLayout, add all our your components in code (TextView, etc), and in your constructor you can read the attributes passed in from the XML. You can then pass that attribute to your title TextView.

http://developer.android.com/guide/topics/ui/custom-components.html