【发布时间】:2014-03-23 04:08:50
【问题描述】:
我为我的班级扩展片段使用了 Merge -Tag。但是当我尝试访问 R 类的元素时遇到了错误。
我的 logcat 显示:“android.view.InflateException: 只能与有效的 ViewGroup 根和 attachToRoot=true 一起使用”。
贝娄是我的source code。请帮我。对不起,我的英语不好。
public class DetailHeader extends Fragment {
ImageView imageView;
TextView textHeader;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LinearLayout wrapper = new LinearLayout(getActivity()); // for example
inflater.inflate(R.layout.detail_header, wrapper, true);
View view = inflater.inflate(R.layout.detail_header, null);
imageView =(ImageView)view.findViewById(R.id.image);
textHeader =(TextView)view.findViewById(R.id.textViewHeader);
imageView.setImageResource(R.drawable.dengiong);
return wrapper;
}
}
这是我的xml file:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textViewHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="20dip"
android:padding="12dip"
android:text="Golden Gate"
android:textColor="#ffffffff" />
</merge>
【问题讨论】:
标签: android xml android-fragments viewgroup