Android的:如何显示一个图像文件(建筑物的楼层图),并更新文件? [英] Android: How to display an image file (building's floor map) and update the file?

查看:217
本文介绍了Android的:如何显示一个图像文件(建筑物的楼层图),并更新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读ImageView的。我想用它来显示图像文件。另外,我有计划提供的功能更新文件。

I have read ImageView. I want to use it to display the image file. Also, I have plan to provide functionality to update the file.

你会教我如何显示图像文件上。然后在顶部添加单选按钮组重新present地板。当我点击一楼,ImageView的来源变化image1.png,然后单击二​​楼单选按钮,切换到image2.png等..

Would you teach me on how to display the image file. Then add group of radio buttons on the top to represent the floors. When I click 1st Floor, the imageview source change to image1.png, then click 2nd floor radio button, change to image2.png and so on..

我使用的是Android 2.1平台,UPDATE1和eclipse ADT对这个论题。

I am using Android Platform 2.1-update1 and eclipse ADT for this thesis.

下面是我目前的code:(虽然有单选按钮的一些不良外观)

Here's my current code: (although there is some undesirable appearance of the radio buttons)

public class DisplayImageMapActivity extends Activity {
    ImageView iv;
    private final String FLOOR = "F";
    private final String storagePath = Environment.getExternalStorageDirectory() + "/keitaiAppH23";
    private final String localMapsPath = storagePath + "/localMaps";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        iv=(ImageView)findViewById(R.id.storageimage);

        RadioGroup levelRGroup = (RadioGroup) findViewById(R.id.level_rgroup);

        int levelSize = 8;
        for (int i = 0; i < levelSize; i++) {
            RadioButton levelRButton = new RadioButton(this);
            if(i==0) {
                levelRButton.setText(new StringBuffer(i+1).append(FLOOR).append("(start)"));
            } else if (i==7) {
                levelRButton.setText(new StringBuffer(i+1).append(FLOOR).append("(end)"));
            }
            levelRButton.setTag((i+1) + FLOOR);
            levelRButton.setLayoutParams(
                    new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));

            levelRGroup.addView(levelRButton);
        }

        levelRGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, final int checkedId) {
                iv.setImageURI(Uri.parse(new StringBuffer(localMapsPath)
                .append("/").append(group.findViewById(checkedId).getTag()).append(".gif").toString()));
                iv.invalidate();
            }
        });

        levelRGroup.getChildAt(0).performClick();

    }
} 

main.xml中

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/main_layout"
    >
    <RadioGroup android:id="@+id/level_rgroup"
        android:layout_width="wrap_content" android:orientation="horizontal"
        android:layout_height="wrap_content">
    </RadioGroup>
    <ImageView android:id="@+id/storageimage" android:src="@drawable/icon"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>

更新:
要求:


  1. 图像文件被动态地设置从外部源获得
    (例如DB,URL)。 - 解决

  2. 单选按钮被需要被动态创建,因为它未通过8F修复。它应该是目标的楼层数(例如开始是5F,到底是7F,所以它应该是3只单选按钮5F,6F,7F)。 - 解决

  1. image file are set dynamically which obtain from external source (e.g. DB,url). - Resolved
  2. radiobuttons are need to be dynamically created because it is not fix by 8F. It should be the number of target floors (e.g. start is 5F, end is 7F, so it should be 3 radiobuttons only 5F,6F,7F). - Resolved

遇到的问题:


  1. 图片不能被更新。 - 解决

  2. 未按预期显示的所有单选按钮(可能由于错误的布局)。 - 尚未解决

  3. 当我点击单选按钮来切换选择,它不会对1F单选按钮更改。注:这是2F至8F确定。它切换为预期的​​选择。 - 解决

  1. Image cannot be updated. - Resolved
  2. All radiobuttons are not displayed as expected (Maybe due to wrong layout). - Not Yet Resolved
  3. When I click the radiobuttons to toggle the selection, it doesn't change on the 1F radiobutton. Note: It is OK for 2F to 8F. It switches the selection as expected. - Resolved

截屏:

推荐答案

这些修改应该这样做(有可能是一些拼写错误):

These modifications should do it (there may be some typos):

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/main_layout"
    >
    <ImageView android:layout_height="wrap_content" android:layout_width="fill_parent" 
                android:id="@+id/iView" android:src="@drawable/icon"></ImageView>

    <RadioGroup android:id="@+id/level_rgroup"
        android:layout_width="fill_parent" android:orientation="horizontal"
        android:layout_height="wrap_content">
        <RadioButton android:id="@+id/rb1"
            android:width="106dip" android:height="80dip" android:text="Floor 1"/>
        <RadioButton android:id="@+id/rb2" 
            android:width="106dip" android:height="80dip" android:text="Floor 2"/>
        <RadioButton android:id="@+id/rb3" 
            android:width="106dip" android:height="80dip" android:text="Floor 3"/>
    </RadioGroup>
</LinearLayout>

code:

public class DisplayImageMapActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);      
            RadioGroup levelRGroup = (RadioGroup) mainLayout.findViewById(R.id.level_rgroup);
            final ImageView iView = (ImageView) findViewById(R.id.iView);

            levelRGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                public void onCheckedChanged(RadioGroup group, final int checkedId) {
                    switch (checkedId) {
                    case R.id.rb1:
                        iView.setImageResource(R.drawable.floor_1);
                        iView.invalidate();
                        break;
                    case R.id.rbM2:
                        iView.setImageResource(R.drawable.floor_2);
                        iView.invalidate();
                        break;
                    case R.id.rb3:
                        iView.setImageResource(R.drawable.floor_3);
                        iView.invalidate();
                        break;
                    }
                }
            }); 
        }
    } 

您可以通过编程添加这些按钮,如果你想,记得设置 layout_width 和其他属性对他们来说,如果你想让他们看到(我把它们放在XML因为我有code周围铺设)。

You can add those buttons programatically if you want to, remember to set layout_width and other attributes for them if you want them to be seen (I put them in the XML since I had that code laying around).

评论,如果您有任何问题。

Comment if you have any questions.

这篇关于Android的:如何显示一个图像文件(建筑物的楼层图),并更新文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆