【问题标题】:Android Stretching Images in NetworkImageView XMLAndroid 在 NetworkImageView XML 中拉伸图像
【发布时间】:2015-06-17 08:29:17
【问题描述】:

我试图弄清楚如何从 TheTVDB(例如 http://thetvdb.com/banners/graphical/84947-g6.jpg)获取电视横幅以适应屏幕宽度。这让我到了那里,但我不想让空白从设置边距:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/poster"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:scaleType="fitXY" />

</LinearLayout>

但是,如果我删除android:layout_margin="8dp",我突然只加载了第一个横幅的一半,但其他横幅都没有出现。

我尝试将width 和/或height 设置为wrap_content 并删除marginscaleType,效果很好,但横幅不会横跨屏幕。

【问题讨论】:

  • 您是否尝试将宽度设置为“match_parent”并将高度设置为“wrap_content”?
  • 是的,我已经尝试同时设置它们以及其中一个。当我这样做时,它会将它们全部放入,但不会将它们拉伸。编辑:如果我按照你提到的方式设置它,它只显示第一条横幅的一半,没有其他内容。

标签: android xml image android-volley networkimageview


【解决方案1】:

HERE 的帖子很有帮助。他最后以编程方式从 WindowManager 获取屏幕宽度的解决方案非常有帮助。

最终像这样做我的:

WindowManager mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Display mDisplay = mWindowManager.getDefaultDisplay();
final int version = Build.VERSION.SDK_INT;
final int width;
if (version >= 13) {
    Point size = new Point();
    mDisplay.getSize(size);
    width = size.x;
} else {
    width = mDisplay.getWidth();
}
myPoster.setLayoutParams(new LinearLayout.LayoutParams(width, 199));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多