[英]ImageView.setImageURI() resets layout?
I'm passing the URI of the resource I want to use to the activity that's supposed to display it with a description. 我正在将要使用的资源的URI传递给本应显示带有描述的活动。 Here's the code: 这是代码:
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);
}
and in the SingleMoveView class: 并在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);
What's happening is I've set up the ImageView and TextView in the XML as such: 发生的事情是我已经在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>
But it's displaying the image in the absolute center of the screen: 但是它将图像显示在屏幕的绝对中心:
Instead of on top w/text underneath. 而不是顶部下方是文本。 [Note the picture isn't displayed. [请注意未显示图片。 view.setImageURI(path); view.setImageURI(path); was commented out] 被注释掉了]
Help please? 请帮助? How do I get it to display properly. 我如何使其正确显示。 Thanks! 谢谢! ^_^ ^ _ ^
Problem solved. 问题解决了。 It was an issue with the dimensions of the picture. 这是图片尺寸的问题。 I had to resize it... 我不得不调整大小...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.