80,350
社区成员
发帖
与我相关
我的任务
分享
package com.view.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
public class AndroidTestDemoActivity extends Activity {
private Button bt, bt2;
private FrameLayout layout;
private FrameLayout container;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
layout.layout(80, 0, 80 + layout.getWidth(), layout.getHeight());
layout.postInvalidate();
}
});
bt2 = (Button) findViewById(R.id.button2);
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
layout.addView(LayoutInflater.from(AndroidTestDemoActivity.this).inflate(R.layout.view, null));
}
});
layout = (FrameLayout) findViewById(R.id.layout);
container = (FrameLayout) findViewById(R.id.container);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Layout" />
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AddView" />
<FrameLayout android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff00ff00" >
<FrameLayout android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff00ff00" />
</FrameLayout>
</LinearLayout>