我在将TextView
s 添加到 Layout 时遇到问题。有些地方没有显示其他人??这是我生成的代码TextView
tv = new TextView(c);
tv.setLayoutParams(lp);
findAndSetAttributes(tv);
tv.setTextSize(22);
tv.setTextColor(Color.BLACK);
if(!isEmpty());
tv.setText(getObjectsContent());
v = tv;
return v;
如果我解析这个 XML 文件,则只显示第一个TextView
,而另一个不显示,但似乎TextView
已添加到布局中但不可见?我尝试过,setVisibility
但没有任何反应。
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="128dp"
android:layout_marginTop="57dp"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/linearLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:ems="10" >
<requestFocus />
</EditText>
<!-- this TextView is displayed?? -->
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentRight="true"
android:layout_marginRight="21dp"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText1"
android:layout_marginLeft="18dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/linearLayout1"
android:text="Button" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button1"
android:layout_marginTop="36dp" />
<TextView>
</TextView>
</LinearLayout>
</RelativeLayout>
编辑 这里“绘制”视图的活动
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.gui);
layout = (LinearLayout) findViewById(R.id.linlayout);
// setResult(RESULT_OK,newIntent);
}
public void drawGUI() {
viewObjects = new View[MainActivity.xm.objects.size()];
viewLayouts = new ViewGroup[MainActivity.xm.objects.size()];
iterativAdd(layout,0);
}
public ViewGroup iterativAdd(ViewGroup root, int from) {
guiObjects gobj;
for(int i =from; i<MainActivity.xm.objects.size();i++) {
gobj = new guiObjects(i);
if(gobj.isLayout()) {
layoutlist.add(MainActivity.xm.objects.get(i));
root.addView(iterativAdd(gobj.makeLayout(this), i+1));
break;
}
else {
viewObjects[i] = gobj.makeObject(this);
if(viewObjects[i]!= null) {
root.addView(viewObjects[i]);
Toast t = Toast.makeText(this, "Object added "+MainActivity.xm.objects.get(i), Toast.LENGTH_SHORT);
t.show();
continue;
}
}
}
return root;
}
我添加其他布局的根布局是线性布局,我不知道这是否是我的正确选择。但我无法弄清楚为什么 Textview 是不可见的???
有任何想法吗?