TableRow 高度被吹爆

发布于 2024-10-01 16:18:06 字数 1968 浏览 1 评论 0原文

我有一个带有 3 个 TableRow 的 TableLayout,每个 TableRow 有 3 个 ImageView。每个 ImageView 都有适合 Scale 类型的 fitCenter,以及每个 stackoverflow 答案。现在所有图像都会缩放以适合该行,但每行都比它需要的要高得多。这是 xml 的摘录:

<TableLayout android:id="@+id/TableLayout01"
android:layout_height="wrap_content"
android:padding="10dip"
android:stretchColumns="0,1,2"
android:shrinkColumns="0,1,2"
android:layout_weight="1"
android:layout_width="wrap_content">
    <TableRow android:id="@+id/TableRow01"
    android:layout_width="fill_parent"
    android:layout_gravity="center_vertical|center_horizontal"
    android:baselineAligned="false"
    android:gravity="center_vertical|center_horizontal"
    android:layout_height="wrap_content">
        <ImageView android:id="@+id/image1"
        android:src="@drawable/avocado3"
        android:scaleType="fitCenter"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"/>
        <ImageView android:id="@+id/image2"
        android:src="@drawable/avocado3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"/>
        <ImageView android:id="@+id/image3"
        android:src="@drawable/avocado3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"/>
    </TableRow>
...
</TableLayout>

这是第一行:

first row

第一行的结尾和第一行的开头第二:

second row

ImageViews 设置为一个小的可绘制对象 (@drawable/avocado3),并在活动的 onCreate 中() 它从互联网上获取 9 个图像并调用 setImageBitmap()。

有人对我做错了什么有任何想法吗?

I have a TableLayout with 3 TableRows, each TableRow has 3 ImageViews. Each ImageView has fitCenter for Scale type, and a weight and width per this stackoverflow answer. Now all the images scale to fit into the row, but each row is way taller then it needs to be. Here's an excerpt of the xml:

<TableLayout android:id="@+id/TableLayout01"
android:layout_height="wrap_content"
android:padding="10dip"
android:stretchColumns="0,1,2"
android:shrinkColumns="0,1,2"
android:layout_weight="1"
android:layout_width="wrap_content">
    <TableRow android:id="@+id/TableRow01"
    android:layout_width="fill_parent"
    android:layout_gravity="center_vertical|center_horizontal"
    android:baselineAligned="false"
    android:gravity="center_vertical|center_horizontal"
    android:layout_height="wrap_content">
        <ImageView android:id="@+id/image1"
        android:src="@drawable/avocado3"
        android:scaleType="fitCenter"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"/>
        <ImageView android:id="@+id/image2"
        android:src="@drawable/avocado3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"/>
        <ImageView android:id="@+id/image3"
        android:src="@drawable/avocado3"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"/>
    </TableRow>
...
</TableLayout>

And here's the first row:

first row

And the end of the first row and start of the second:

second row

The ImageViews are set to a drawable that is small (@drawable/avocado3), and in the activity's onCreate() it fetches 9 images from the internet and calls setImageBitmap().

Anyone have any ideas on what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

默认情况下,scaleType 仅更改实际图像的大小,但不会更改周围 ImageView 的大小。由于 ImageView 的高度设置为 wrap_content,因此它将占用显示完整图像所需的所有空间,然后缩放图像以使其适合其宽度。

尝试将 adjustViewBounds 设置为 true。如果这没有帮助,请尝试设置固定的 layout_height 或使用 maxHeight 属性。

查看层次结构查看器内部也可能有所帮助: http:// developer.android.com/guide/developing/tools/hierarchy-viewer.html

By default, scaleType only changes the size of the actual image, but not the size of the surrounding ImageView. Since the height of the ImageView is set to wrap_content, it will take all the space it needs to display the full image, and then scale the image to fit it inside it's width.

Try setting adjustViewBounds to true. If that doesn't help, try setting a fixed layout_height or play around with the maxHeight property.

It might also help to take a look inside the hierarchy viewer: http://developer.android.com/guide/developing/tools/hierarchy-viewer.html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文