我在向布局添加TextView
时遇到问题。有些地方显示其他人不?
这是我生成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;
}
我的根布局,我添加其他布局是一个LinearLayout我不知道这是否是我的正确选择。 但我无法弄清楚为什么Textview不可见???
任何想法?