I'm trying to figure out how to get TV banners from TheTVDB (example http://thetvdb.com/banners/graphical/84947-g6.jpg) to fit the screen width. This gets me the there but I don't want to have the white space from setting the margin:
<?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>
However if I remove the android:layout_margin="8dp"
I suddenly just get half of the first banner loaded but none of the others appear.
I've tried setting it the width
and/or height
to wrap_content
and removing the margin
and scaleType
, that works fine, but the banners do not stretch across the screen.
The post HERE was very helpful. His solution at the end to programaticly get the width of the screen from WindowManager was very helpful.
Ended up doing mine like so:
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));