Layout 调用 layoutlayout(int l, int t, int r, int b) 方法后 变换了位置
但是在调用了 addView 方法后 位置又变了回去
AndroidTestDemoActivity.java
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);
}
}main.xml
<?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>view.xml
[code=XML]<?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"
android:background="@android:color/white" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>/code]怎样操作 才能使 layout变换位置后 addView 位置 不会改变
但是在调用了 addView 方法后 位置又变了回去
AndroidTestDemoActivity.java
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);
}
}main.xml
<?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>view.xml
[code=XML]<?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"
android:background="@android:color/white" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>/code]怎样操作 才能使 layout变换位置后 addView 位置 不会改变
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货