Как сделать так чтобы элемент <View был поверх остальны (сейчас его не видно ) :…
- User
Как сделать так чтобы элемент <View был поверх остальны (сейчас его не видно ) : <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="200dp" app:cardCornerRadius="4dp" app:cardElevation="2dp">
code<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <View android:layout_width="125dp" android:layout_height="match_parent" android:backgroundTint="@color/red" android:elevation="2dp" /> <ImageView android:id="@+id/cardBackgroundImage" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:scaleType="centerCrop" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:minHeight="72dp" android:orientation="horizontal"> <!-- Первая иконка --> <ImageView android:id="@+id/icon1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:src="@drawable/icon1" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.6" android:text="Title" android:textStyle="bold" android:textColor="@color/white"/> <ImageView android:id="@+id/icon2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.2" android:src="@drawable/icon2" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:text="Genre" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/cardBackgroundImage" android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:text="Rating" android:textStyle="bold" /> </RelativeLayout> - Assistant
Чтобы элемент был поверх остальных, вам нужно изменить порядок размещения элементов в RelativeLayout. Вместо того, чтобы помещать перед другими элементами, поместите его после . Вот обновленный код:
code<ImageView android:id="@+id/cardBackgroundImage" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:scaleType="centerCrop" /> <View android:layout_width="125dp" android:layout_height="match_parent" android:backgroundTint="@color/red" android:elevation="2dp" /> <!-- Остальные элементы оставьте без изменений -->Теперь элемент будет находиться выше других элементов и будет виден поверх них.
- User
не помогла , элемент все так же не видно
- Assistant
Попробуйте добавить атрибут
android:translationZс положительным значением для элемента . Это установит его z-позицию поверх других элементов. Вот обновленный код:code<View android:layout_width="125dp" android:layout_height="match_parent" android:backgroundTint="@color/red" android:elevation="2dp" android:translationZ="10dp" />Измените значение
android:translationZпо своему усмотрению, чтобы элемент был достаточно видимым поверх остальных элементов.