【发布时间】:2014-01-10 04:22:43
【问题描述】:
我在一个行为不端的 Android 应用中有一个布局。现在,它看起来像这样:
我们的想法是让 3 张图像及其反射作为单独的图像排列在它们下方。如果我只有图像(只有第一个嵌套的 LinearLayout,如下所示),那么图像显示得很好,它们的原始分辨率和均匀间隔。但是在添加了第二个线性布局(反射)后,显示的图像比应有的要小得多。
图片中的那些反射图像显示的尺寸正确,并且图像本身应该与反射一样宽。如果它们正确显示,则图像顶部到反射底部应该填满屏幕的高度。但他们不是。我已经在图像视图和线性布局(也是不同的 scaleTypes)上尝试了很多 layout_width 和 layout_height 的组合,但没有什么能阻止图像由于某种原因缩小。谁能提出原因?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- IMAGES -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<!-- IMAGE REFLECTIONS -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
另外,我并没有死心塌地使用 LinearLayouts,因此欢迎提供替代想法。
更新:
这是为每个 ImageView 添加背景颜色后的外观:
...这就是它的实际外观。这是通过将每个海报 ImageView 的 layout_width 和 layout_height 分别设置为 333px 和 500px 来实现的。但我不想这样做。当屏幕上显示的图像少于 3 张时,它会导致海报和反射之间的水平对齐问题:
【问题讨论】:
标签: android android-layout android-linearlayout android-imageview android-xml