0

I'm not sure exactly why but I'm attempting to set the size of my thumbnails to fill parent however it does not appear they are doing so and I'm unsure why.

I've set the parameters as (I believe) they should be but the thumbnail still will not stretch to the edges of the screen.

SCREENSHOT

enter image description here

XML

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/groupScrollView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Throw &apos;Em Up"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by DJ Generic"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bulls On Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by Rage Against the Machine"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Isaac Daniel at CNN Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="678,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>
        </LinearLayout>
    </ScrollView>

</LinearLayout>
JavaNoob
  • 75
  • 4
  • 15

2 Answers2

10

Add android:adjustViewBounds="true" to your View.

I did:

<com.google.android.youtube.player.YouTubeThumbnailView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"/>

And the Thumbnail match my parent layout keeping its 16:9 ratio.

Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
megaturbo
  • 680
  • 6
  • 24
0

I managed to fix this by working with the aspect ratio best practices stated by google for youtube thumbnails (https://support.google.com/youtube/answer/72431?hl=en).

They state that a thumbnail should have a 16:9 aspect ratio so when I create the view, I get it's parent width and calculate the height based on that. I couldn't find any other way to scale the thumb image to fit the screen width (the YoutubeThumbnailView is scaled but the image inside it is not).

    View parentView = activity.findViewById(parentId);
    int parentWidth = parentView.getWidth();
    int youtubeThumbnailHeight = (int) (parentWidth * aspectRatioY / aspectRatioX);
    thumb.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, youtubeThumbnailHeight));

Where aspectRatioY is 9 and aspectRatioX is 16.

I know that it's not a good solution, but after searching for a while with no results, this is the best I could do. Hope it helps.

Spiri
  • 1,283
  • 11
  • 24