2

Делаю вывод превью у видео как вконтакте, но к сожалению, есть проблема при смене в горизонтальную ориентацию. Как сделать так, чтобы градиент и надписи накладывались только на изображение, как на первом скриншоте?

    <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>

До это использовал свойство fitXY в ImageView, но высота у изображения фиксированная. Каковы методы реализации?

Как должно быть

То, что сейчас

1
  • FrameLayout width пробовали поменять на wrap_content ?
    – Iman
    16 янв 2017 в 19:11

2 ответа 2

1
<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>
0

Попробуйте поменять FrameLayout и Viewвот так:

        <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"/>
1
  • Не помогло, разве что View ушло позади ImageView.
    – Holofox
    17 янв 2017 в 10:55

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.