【问题标题】:ImageViews in a ListView not aligned vertically [Mono for Android]ListView 中的 ImageViews 未垂直对齐 [Mono for Android]
【发布时间】:2012-01-09 06:02:01
【问题描述】:

我是开发安卓应用的新手,请耐心等待。

话虽如此,我正在尝试制作一个列表,其中左侧是图像,图像右侧是标题和说明。

图像在后台从网络下载,然后在完成后在 UI 中设置。这一切都有效。但是,图像没有正确对齐,我根本无法理解为什么。我认为这与 xml 文件中定义的布局有关吗?我尝试使用 android:layout_alignParentLeft="true"android:layout_gravity="left" 但这让我无处可去。

然后我不知道如何继续,即使在谷歌上搜索了我能想到的所有方法之后。如果这是非常基本的,我很抱歉,但我真的很感谢这里的一些帮助。

这是一张照片:

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget28"
    android:layout_width="fill_parent"
    android:layout_height="80px"
>
    <ImageView
    android:id="@+id/imageItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_alignParentLeft="true"
    >
    </ImageView>
    <LinearLayout
    android:id="@+id/linearText"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_marginLeft="10px"
    android:layout_marginTop="10px"
        >
        <TextView
        android:id="@+id/textTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
            >
        </TextView>
        <TextView
        android:id="@+id/textBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
            >
        </TextView>
        </LinearLayout>
</LinearLayout>

感谢您提供的任何帮助。

【问题讨论】:

    标签: android mono imageview alignment xamarin.android


    【解决方案1】:

    有两种方法可以实现您的愿望:

    1.修复ImageView的宽高,使用android:scaleType="fitXY"。这听起来很糟糕,但实际上我所知道的几乎画廊应用程序都在缩略图预览模式下使用它。

    2.设置android:scaleType="fitStart"。不能保证这会起作用,取决于图像源的宽度和高度的比率。但是如果你所有的图片来源都是横向风格(宽度>高度),这种方式应该可以工作。

    【讨论】:

    • 因为我所有的图片都是横向的,所以我先尝试了#2。那成功了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-03-04
    • 2019-07-02
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 2019-05-20
    • 1970-01-01
    相关资源
    最近更新 更多