【发布时间】:2012-01-24 11:17:59
【问题描述】:
我用一个 Activity 编写了一个简单的 Hello World 应用程序。
类:
public class HelloWorld extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.helloworld);
}
}
helloworld.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/>
我有所需的资源和“AndroidManifest.xml”,应用程序运行良好。
在“hierarchyviewer”工具的“View Hierarchy window”中,我注意到 TextView 小部件的父级是 FrameLayout,其父级是 LinearLayout(为简洁起见,我只剪切了所需的屏幕截图)。屏幕截图:
在我的“helloworld.xml”中,我没有将 FrameLayout 声明为 TextView 小部件的父级。请帮助我理解:
1. 一般来说,如果布局资源(xml文件)中没有显式声明布局,运行时如何决定布局?
2. 图中为什么LinearLayout是FrameLayout的parent?
非常感谢。
【问题讨论】:
标签: android android-layout android-activity default