TextView不添加片段布局

时间:2013-02-21 05:32:24

标签: android android-layout android-fragments

我有一个包含片段的主细节活动。我尝试在详细片段中动态添加TextView。但它并没有增加细节片段布局。但布局正确显示。

片段代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    View rootView = inflater.inflate(
            R.layout.fragment_configuration_detail, container, false);
    RelativeLayout cdf_detail_part1=((RelativeLayout) rootView.findViewById(
            R.id.cdf_detail_part1));

    Log.i("config", "mItem1->"+mItem1);
    if (mItem1 != null) {
        TextView name_text = (TextView) cdf_detail_part1.findViewById(
                R.id.cdf_tv_name);
        name_text.setText(name);
    }

    return rootView;
}

我的布局XMl文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="horizontal"
    tools:context="com.x.y.configurations.ConfigurationDetailFragment" >

    <RelativeLayout
        android:id="@+id/cdf_detail_part1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#00FF00" >

        <TextView
            android:id="@+id/cdf_tv_name"
            style="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

      </RelativeLayout>

    <RelativeLayout
        android:id="@+id/cdf_detail_part2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
         android:background="#0000FF" >
    </RelativeLayout>

</LinearLayout>

0 个答案:

没有答案