0

我试图弄清楚如何从 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"我突然只加载了第一个横幅的一半,但其他横幅都没有出现。

我尝试将其设置为and width/or并删除and ,效果很好,但横幅不会在屏幕上伸展。heightwrap_contentmarginscaleType

4

1 回答 1

0

这里的帖子很有帮助。他最后以编程方式从 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));
于 2015-04-24T03:10:22.440 回答