【问题标题】:Android image display full height - loaded asynchronouslyAndroid图像显示全高-异步加载
【发布时间】:2015-07-31 20:04:16
【问题描述】:

嘿,我从 Android 开始我的冒险,但我无法解决一个问题。 我正在使用 Universal Image Loader 从 Web 服务器加载图片。我将它们放入位于 ListView 中的相对布局中。我想要达到的效果,就是图片全宽全高显示在整个屏幕上,底部有一个小框。 在 IDE 预览中,一切正常:

但在我的手机上加载的图像看起来像这样。我希望它们以全高显示。是否需要使用编程函数来实现?

加载图片:

imageLoader.displayImage(
                wallpapers.get(position).getSrcUrl()//the drawable
                , currentWallpaperViewHolder.imageViewWallpaper//the image view
                , imageLoaderOptions);//the display options

return itemView;

列表视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
>
<ListView
    android:id="@+id/WallpapersListView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

图像视图:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<ImageView
    android:id="@+id/wallpaper_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    android:src="@drawable/test"
     />

<TextView
    android:id="@+id/wallpaper_date_for_use"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dip"
    android:padding="12dip"
    android:background="#AA000000"
    android:textColor="#ffffffff"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:textStyle="bold"
    android:text="Date of use" />
</RelativeLayout>

【问题讨论】:

    标签: android android-layout android-imageview android-view universal-image-loader


    【解决方案1】:

    这可能是因为您有一个 RelativeLayout 作为您的根视图。尝试将外部的 RelativeLayout 包装在 LinearLayout 中。

    【讨论】:

    • 我的根视图是线性布局。对不起,如果这不是很清楚:) 在 LinearLayout 我有 ListView,带有 RelativeLayouts 的集合
    • 这是整个代码。代码分为两个视图——ListView和RelativeLayout来显示图片。
    【解决方案2】:

    你可以这样做,

    1. 获取设备高度。
    2. 然后以编程方式将 imageView 高度设置为设备高度。

    【讨论】:

    • 我知道我可以通过编程来完成。作为开始使用 Android 冒险的人,我想知道是否可以仅使用视图参数来完成?
    • 那么你可以使用被滚动视图包围的LinearLayout而不是使用ListView。它会解决你的问题。然后以编程方式添加每个 LinearLayout。
    • 所以我尝试了你的解决方案,但效果是一样的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多