在 Framelayout 中,我有 1 个卡片视图和一个图像视图我想要卡片视图上的图像视图我想做的事

问题描述

我试图在卡片视图上创建图像视图。所以我使用了Framelayout。在里面我添加了 1 cardview 之后我添加一个图像视图。如果我使用 LinearLayout 而不是 cardview,则图像视图会通过线性布局进行查看。但是,如果我使用卡片视图,则图像视图不会超过卡片视图。请帮我 ... I have shown what I have

解决方法

把你的卡片视图放在 AnyLayout 中,比如 LinearLayout

<FrameLayout>
 <LinearLayout>
   <CardView/>
 </LinearLayout>
 <ImageView/>
</FrameLayout>
,

尝试以下内容:

   <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CustomGallery"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="Dummy Text"
        android:gravity="center"/>

<!--  Add more Views -->

    <FrameLayout
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:clickable="true"
        android:layout_marginStart="20dp"
        android:layout_marginEnd="20dp"
        android:layout_gravity="center_horizontal">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:cardCornerRadius="10dp"
            app:cardElevation="0dp">
            <!--<ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/add_menu_item_logo"
                android:scaleType="fitXY"
                android:src="@drawable/ic_baseline_brightness_low_24"
                />-->
        </androidx.cardview.widget.CardView>
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/add_menu_logo_placeholder">
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:src="@drawable/ic_baseline_brightness_low_24"/>
        </FrameLayout>
    </FrameLayout>
</LinearLayout>
,

请像这样使用卡片视图

       <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:cardElevation="0dp" 
            android:elevation="0dp"
            android:layout_centerInParent="true" />

注意重要的属性是 应用程序:cardElevation="0dp" 和 android:elevation="0dp" 它将高程设置为 0。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...