1.在res/layout目录下创建布局资源如activity_simple_resource_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background_color">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="18dp"
android:gravity="center"
android:text="@string/test_string"
android:textColor="@color/text_color"
android:textSize="18sp" />
</LinearLayout>
2.获取布局资源
//获取布局资源中的文本对象
TextView txt = (TextView)findViewById(R.id.textView1);
Log.d(DEBUG_TAG, "textView1="+txt.getText());
//获取布局资源
XmlResourceParser myMainXml = getResources().getXml(R.layout.activity_paris_view);
Log.d(DEBUG_TAG, "myMainXml="+ myMainXml);