I do a preview of the video as VKontakte, but unfortunately, there is a problem when changing to horizontal orientation. How to make so that the gradient and labels are superimposed only on the image, as in the first screenshot?

<FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/photo" android:layout_width="match_parent" android:layout_height="200dp" android:adjustViewBounds="true" android:scaleType="fitCenter"/> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/gradient"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="vertical" android:paddingBottom="10dp" android:paddingLeft="@dimen/feed_item_profile_info_padd" android:adjustViewBounds="true"> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:text="Title" android:textColor="@color/cardview_light_background" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/views" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="100 просмотров" android:textColor="@color/vk_share_gray_line" android:textSize="14sp" android:textStyle="normal" /> </LinearLayout> </FrameLayout> 

Prior to this, I used the fitXY property in ImageView, but the image height is fixed. What are the implementation methods?

It should be

What is now

  • FrameLayout width tried to change to wrap_content? - Iman

2 answers 2

 <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/photo" android:layout_width="wrap_content" android:layout_height="200dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:adjustViewBounds="true" android:scaleType="fitXY" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/photo" android:layout_alignParentBottom="true" android:layout_alignRight="@+id/photo" android:background="@drawable/gradient" android:orientation="vertical" android:paddingBottom="10dp" android:paddingLeft="@dimen/feed_item_profile_info_padd" android:paddingTop="5dp"> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:text="Title" android:textColor="@color/cardview_light_background" android:textSize="15sp" android:textStyle="bold" /> <TextView android:id="@+id/views" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="100 просмотров" android:textColor="@color/vk_share_gray_line" android:textSize="14sp" android:textStyle="normal" /> </LinearLayout> </RelativeLayout> 

    Try changing FrameLayout and View like this:

      <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <View android:layout_width="match_parent" android:layout_height="200dp" android:background="@drawable/gradient"/> 
    • It did not help, except that View was gone behind ImageView. - Holofox