来自xml布局的生成代码

时间:2014-06-30 15:54:01

标签: android 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" >    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test">
        </TextView>    
</LinearLayout>

我想从布局生成代码:

LinearLayout layout = new LinearLayout(context);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layout.setLayoutParams(lp);
layout.setOrientation(LinearLayout.VERTICAL);

TextView textview = new TextView(context);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(lp);
textview.setText("test");
layout.addView(textview);

有人可以知道这方面的工具吗?

0 个答案:

没有答案