ImageView.setImageURI()重置布局?

时间:2013-09-29 04:44:04

标签: java android

我将要使用的资源的URI传递给应该用描述显示它的活动。这是代码:

        public void onClick(View v) {
            final String root = "android.resource://" + getPackageName() + "/";
            Intent myIntent = new Intent( v.getContext(), SingleMoveView.class);
            myIntent.setData(Uri.parse(root + R.drawable.simby));
            myIntent.putExtra("Desc", getResources().getString(R.string.simbus));
            startActivity(myIntent);
        }

并在SingleMoveView类中:

    ImageView view = (ImageView) findViewById(R.id.singleMoveView);
    TextView text = (TextView) findViewById(R.id.singleMoveDesc);

    Uri path = getIntent().getData();
    String desc = getIntent().getStringExtra("Desc");

    view.setImageURI(path);
    text.setText(desc);

我发生了什么?我在XML中设置了ImageView和TextView:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:theme="@android:style/Theme.Holo.NoActionBar">

    <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/singleMoveView"
            android:layout_margin="20dp"/>

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:id="@+id/singleMoveDesc"
            android:layout_margin="20dp"
            android:layout_below="@+id/singleMoveView"
            android:layout_alignParentLeft="true"/>
</RelativeLayout>

但是它在屏幕的绝对中心显示图像: What it is doing

而不是在下面的文本上面。 [注意图片没有显示。 view.setImageURI(路径);被评论出来了]

What it should be doing

请帮忙吗?如何让它正确显示。谢谢! ^ _ ^

1 个答案:

答案 0 :(得分:0)

问题解决了。这是图片尺寸的问题。我不得不调整它的大小......