[英]About Android Layout File
I would like to know about custom layout xml files in Android. 我想了解Android中的自定义布局xml文件。 I came across a code block that tells
我遇到了一个代码块,它告诉
<org.superboy.ui.OnlineShop xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sp_title"
android:layout_width="fill_parent"
android:layout_height="38dip"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:background="@drawable/shop_background"
>
There is a file called OnlineShop.java
in the src/org/superboy/ui
I did not understand about creating such layouts other than default layout files that we create for activities. 除了我们为活动创建的默认布局文件以外,我不了解关于创建此类布局的
src/org/superboy/ui
有一个名为OnlineShop.java
文件。 Any help pointing to such layouts or advice. 指向此类布局或建议的任何帮助。
You can create anything such as TextViews etc. through a class and extend TextView, and then in your XML layout just add an item like above. 您可以通过一个类创建诸如TextViews之类的任何东西并扩展TextView,然后在您的XML布局中仅添加上述项。 Here is an example of a ResizeableTextView I made and an XML layout.
这是我制作的ResizeableTextView和XML布局的示例。
You will see that the OnlineShop.java
class will extend something like the following : 您将看到
OnlineShop.java
类将扩展如下内容:
ViewGroup
View
LinearLayout
RelativeLayout
ect. RelativeLayout
。 These all are objects that can be used in your xml file as a View
. 这些都是可以在xml文件中用作
View
。 We call them custom Views
. 我们称它们为自定义
Views
。
You create custom Views
when you have a specification in your app that cannot be handled by the standard View
controls that Android provided (which will not be often because the default View
controls are very versatile). 当您的应用中有规范时,您可以创建自定义
Views
,而规范不能由Android提供的标准View
控件处理(因为默认的View
控件用途广泛,因此通常不会出现)。
You can go read up on it here 你可以在这里阅读
Hope this helps 希望这可以帮助
You must make sure that your OnlineShop.java file resides in which package, if your java file resides in your.project.package
then you must change your layout file as 您必须确保OnlineShop.java文件位于哪个包中,如果java文件位于
your.project.package
则必须将布局文件更改为
<your.project.package.OnlineShop xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sp_title"
android:layout_width="fill_parent"
android:layout_height="38dip"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:background="@drawable/shop_background"
>
Now compiler will refer your onlineShop.java file from your packages. 现在,编译器将从包中引用您的onlineShop.java文件。
general information 一般信息
when we place any XML code in our layout file let suppose bellow code 当我们在布局文件中放置任何XML代码时,假设以下代码
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
it looks our layout file from android.jar package which are included automatically in eclipse while making a new android project. 它会从android.jar包中查找我们的布局文件,该文件会在制作新的android项目时自动包含在eclipse中。
So if you make any custom layout then you have to create your own java class extending from any view or viewgroup
in your own package and it should be declared in your XML file mentioning your package see my above code 因此,如果您进行任何自定义布局,则必须创建自己的Java类,该类从您自己的包中的任何
view or viewgroup
组扩展而来,并且应在提及您的包的XML文件中声明它,请参见上面的代码
Hope this helps :) 希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.