2010-11-04 32 views
0

我正试图在我的主视图上显示一个新视图。Android查看未出现

这里是新的视图中的XML:

<RelativeLayout 
     android:id="@+id/mapdetaillayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="left" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

      <TextView 
       android:text="This is the Text from the XML File." 
       android:id="@+id/DetailTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 

    </RelativeLayout>  

这里是我使用推新viev到屏幕上的代码:

 RelativeLayout DetailLayout = new RelativeLayout(c); 

     LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View v = inflater.inflate(R.layout.mapdetailview, DetailLayout);  

     TextView tv = (TextView) v.findViewById(R.id.DetailTextView); 
     tv.setText("HERE IS THE TEXT FROM THE CODE"); 

     // This Log works 
     Log.i("MESSAGE", tv.getText()); 

     DetailLayout.setBackgroundColor(Color.WHITE); 

     LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     params.gravity = Gravity.NO_GRAVITY; 

     DetailLayout.bringToFront(); 
     DetailLayout.setVisibility(View.VISIBLE); 

代码被调用,Log输出预期的文本,这对我来说意味着View已经被创建 - 它只是不显示在屏幕上。

任何帮助,将不胜感激。

回答

3

我在代码中看不到任何对Activity的setContentView()方法的调用。可能你只是不这样做?如果是这样,那就是你什么都看不到的原因。你也不需要手动使用RelativeLayout。尝试只指定布局资源为内容的看法:

setContentView(R.layout.mapdetailview); 

然后,您可以只是让你的TextView:

TextView tv = (TextView) findViewById(R.id.DetailTextView); 

我希望帮助。

+0

为什么你这样做?看起来对我来说完全错了。 – 2010-11-05 02:56:14

0

您是否尝试将LayoutParams.WRAP_CONTENT更改为fill_parent以查看是否有任何更改?