Android 是否可以使用xml文件创建图像
我试图通过xml文件创建一个图像。请问是否有可能这样做 下面是我想要创建为图像的XML文件的代码,以便在imageview中显示 主要活动Android 是否可以使用xml文件创建图像,android,bitmap,touch,imageview,Android,Bitmap,Touch,Imageview,我试图通过xml文件创建一个图像。请问是否有可能这样做 下面是我想要创建为图像的XML文件的代码,以便在imageview中显示 主要活动 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main)
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner2 = (Spinner) findViewById(R.id.spinner1);
imageshow =(ImageView) findViewById(R.id.imageshow);
items = fillMaps();
SimpleAdapter adapter=new SimpleAdapter(this,items,R.layout.spinner,
new String[]{"name"},
new int[]{R.id.title});
spinner2.setAdapter(adapter);
spinner2.setOnItemSelectedListener(new MyOnItemSelectedListener());
spinner2.setVisibility(View.VISIBLE);}
Layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bible_help_title" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/bible_help_title">
<Spinner
android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/bible_help_title"
android:drawSelectorOnTop="true"
/>
</RelativeLayout>
<ImageView
android:id="@+id/imageshow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/layout_1"/>
</RelativeLayout>
原始文件夹中的表_1.xml的代码
img_101.jpg
img_102.jpg
table_1.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/white"
android:orientation="vertical"
>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eric Graduation" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="17" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="peter birthday" />
</TableRow>
</TableLayout>
我不知道你这样做的理由是什么 如果您只想在ImageView中显示一些视图结构作为图像,那么有一种更简单的方法 使用LayoutInflator将您的桌面布局正常充气。一旦有了对它的引用,就可以调用以获取可以传递到ImageView的位图对象
Bitmap mImg = tbl.getDrawingCache();
mImgView.setImageBitmap(mImg);
我之所以要这样做,是因为我有一个微调器,供用户从列表中选择资源。有些资源是图像格式,有些资源是表格格式[所有资源都放在原始文件夹中]。因此,我想将xml文件转换为图像,以便在imageview中显示它。我已经更新了代码并给出了更多解释,您可以看看它是否更清晰吗?嗨,Tim。。。你对我的问题有什么建议吗?先谢谢你
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/white"
android:orientation="vertical"
>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eric Graduation" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="17" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="peter birthday" />
</TableRow>
</TableLayout>
Bitmap mImg = tbl.getDrawingCache();
mImgView.setImageBitmap(mImg);