我正在使用以下代码在其子 LinearLayout 下扩展我的布局中的视图:
LayoutInflater vi = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.your_layout, null);
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.a_text_view);
textView.setText("your text");
// insert into main view
View insertPoint = findViewById(R.id.insert_point);
((ViewGroup) insertPoint).addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
但我在那里看不到我的观点。当我将屏幕旋转到横向视图时,它会显示出来。如何解决这个问题?
编辑:
这基本上就是我正在做的事情。我有一个带有两个选项卡的 TabActivity。我使用一个应用程序全局存储我的 TabActivity 的标志和 TabHost。我还在第二个选项卡活动中使用了一个线程,该线程持续监视应用程序全局以监视标志。当我单击第一个选项卡中的按钮时,我将全局设置为 true。第二个选项卡中的线程检查其值。当它成立时,我运行异步任务并使用我在 ApplicationGlobal 中搅拌的 TabHost 将当前显示窗口转移到第二个选项卡。
第二个标签的代码:
public class ShowDownloadsActivity extends Activity {
private List<String> list;
ApplicationGlobal ap;
String tempUrl = "";
LinearLayout lly;
LayoutInflater inflater;
Context con;
static int k = 0;
static int tmp = 0;
static int size = 0;
View insertPoint;
View v;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shwds);
con = this;
v = LayoutInflater.from(this).inflate(R.layout.downloadlistrow, null);
insertPoint = (View) findViewById(R.id.layout_vids);
inflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ap = (ApplicationGlobal) getApplication();
lly = (LinearLayout) findViewById(R.id.layout_vids);
Thread thread1 = new Thread() {
public void run() {
try {
boolean flg = ap.getFlag();
if (flg) {
tempUrl = ap.getUrl();
ap.setUrl("");
flg = false;
new downloadVideo().execute();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread1.run();
}
class downloadVideo extends AsyncTask<Hashtable<String, String>, String, String> {
String resp = "";
protected void onProgressUpdate(String... values) {
}
@Override
protected void onPreExecute() {
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.siz);
textView.setText("your text");
// insert into main view
addContentView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
super.onPreExecute();
}
@Override
protected String doInBackground(Hashtable<String, String>... prmss) {
try {
final int return resp;
}
@Override
protected void onPostExecute (String result){
super.onPostExecute(result);
}
}
}
}