实例:LayoutDemo
运行效果:
代码清单:
布局文件:frame_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg"
/>
</FrameLayout>
android:id 定义组件的id,在应用程序中,我们通过这个id就可以访问到定义的这个元素。
android:layout_width="match_parent" 和android:layout_height="match_parent" 表示FrameLayout布局可以在x轴方向和y轴方向填充满父容器的空间。
android:layout_width="wrap_content" 和android:layout_height+"wrap_content" 表示ImageView元素的长和宽只需要将bg.jpg包裹起来即可,并不需要填充满父容器。
Java源代码文件:FrameLayoutActivity.java
package com.rainsong.layoutdemo;
import android.app.Activity;
import android.os.Bundle;
public class FrameLayoutActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.frame_layout);
}
}
1389




被折叠的 条评论
为什么被折叠?



