框架布局FrameLayout
一、简介
二、代码实例
结果图:
代码:
需要注意的代码:
imageView_play.setVisibility(View.INVISIBLE);
<FrameLayout
framelayoutfry2.MainActivity
package framelayoutfry2; import com.example.framelayoutfry2.R; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView; public class MainActivity extends Activity implements OnClickListener{
private Button btn_play;//创建一个button对象
private Button btn_pause;//创建一个button对象
private ImageView imageView_play;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//父类操作
setContentView(R.layout.activity_main);//引入名为activity_main的界面
imageView_play=(ImageView) findViewById(R.id.imageView_play);
btn_play=(Button) findViewById(R.id.btn_play);
btn_pause=(Button) findViewById(R.id.btn_pause);
btn_play.setOnClickListener(this);
btn_pause.setOnClickListener(this); }
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_play:
imageView_play.setVisibility(View.INVISIBLE);
break;
case R.id.btn_pause:
imageView_play.setVisibility(View.VISIBLE);
break;
default:
break;
}
}
}
/Test_FrameLayout/res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > 7 <FrameLayout
8 android:layout_width="match_parent"
9 android:layout_height="wrap_content"
10
11 >
12 <ImageView
13 android:layout_width="match_parent"
14 android:layout_height="250dp"
15 android:src="@drawable/frame_bg"
16 />
17
18 <ImageView
19 android:id="@+id/imageView_play"
20 android:layout_width="35dp"
21 android:layout_height="35dp"
22 android:src="@drawable/play"
23 android:layout_gravity="bottom"
24 android:layout_marginBottom="38dp"
25 />
26
27 </FrameLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="播放"
android:layout_weight="1"
/> <Button
android:id="@+id/btn_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="暂停"
android:layout_weight="1"
/> </LinearLayout> </LinearLayout>