我无法在XML Android中调整图像大小

时间:2014-10-12 21:43:09

标签: java android xml android-imageview resize-image

为什么我无法以大尺寸显示图像,结果更小,我的XML代码有问题吗?或者错误在java代码中?我在ImageView中的XML代码上有“[Accessibility]在图像上缺少contentDescription属性” Poster

这是我的代码:

Detail.xml

<ImageView
        android:id="@+id/ivPosterImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:maxHeight="300dp"
        android:src="@drawable/large_movie_poster" />
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ivPosterImage"
        android:layout_marginTop="10dp" android:id="@+id/scrollView1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

Activity.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_box_office_detail);
        // Fetch views
        ivPosterImage = (ImageView) findViewById(R.id.ivPosterImage);
        ....
Picasso.with(this).load(movie.getLargePosterUrl()).
            placeholder(R.drawable.large_movie_poster).
            into(ivPosterImage);

请帮帮我......

1 个答案:

答案 0 :(得分:0)

它清楚地看到您下载的图像具有非常小的高度和宽度尺寸,并且您已经围绕wrap_content确定了尺寸。这就是为什么你得到这个小图标而不是完整图像的原因。

同样,图像下载库总是在其代码中使用图像属性setSource,它还在wrap_content周围设置图像。

现在您有2种选择来展示更广泛的图像:

  1. set width = match parent,    高度=固定(根据您的选择任意值,如100 dp,200等),我没有固定宽度,因为那是goona在小型或大型screns上创建异常。

  2. 设置图像背景而不是默认由图像下载库设置的图像src。

  3. 希望这可以解决您的问题。