【发布时间】:2017-11-11 14:25:56
【问题描述】:
我在数组中有某些图片链接,我通过为数组中的每张图片创建一个 ImageView 并将其放置在 LinearLayout 中来显示它。如果数组中只有一张或两张图片,这似乎可行,但是当有两张以上的图片时,图片会被切断。此外,我还想以原始尺寸显示图像。
XML 代码:
<LinearLayout
android:id="@+id/child_2_5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="3dp"
android:orientation="horizontal"
android:layout_below="@+id/child_2_4">
</LinearLayout>
MainActivity.java 代码:
LinearLayout layout = (LinearLayout) findViewById(R.id.child_2_5);
for(int i=0; i<values1.length; i++) {
ImageView image = new ImageView(this);
image.setLayoutParams(new android.view.ViewGroup.LayoutParams(450,450));
Glide.with(Main2Activity.this).load(values1[i]).into(image); // I am using Glide to display images
layout.addView(image);
}
这里values1 = [https://drive.google.com/uc?export=view&id=0B6uiOVPlyIu-dnlFdTlZQ1lFNDA, https://drive.google.com/uc?export=view&id=0B6uiOVPlyIu-bUI1ZV9wY0R3cTQ, https://drive.google.com/uc?export=view&id=0B6uiOVPlyIu-WFpXeWVlZ01zX2c]
您可以看到边缘被切割,图片不是这个原始尺寸。
【问题讨论】:
-
您可以使用 imageview 的 scaletype 属性在 imageview 中对齐。
标签: android android-layout imageview android-linearlayout