【问题标题】:Inside Framelayout i have 1 cardview and an image view. I want the image view over the card view. What i want to do在 Framelayout 内,我有 1 个卡片视图和一个图像视图。我想要卡片视图上的图像视图。我想做的事
【发布时间】:2021-09-02 04:11:47
【问题描述】:

我试图在卡片视图上创建一个图像视图。所以我使用了Framelayout。在里面我添加了 1 个卡片视图,然后我添加了一个图像视图。如果我使用 LinearLayout 而不是 cardview,则图像视图会在 linearlayout 上显示。但是,如果我使用卡片视图,则图像视图不会超过卡片视图。请帮我 ... I have shown what I have

【问题讨论】:

  • 请告诉我们你尝试了什么?
  • 嗨南达库玛。欢迎来到 StackOverflow。请将您的代码直接粘贴到问题中。屏幕截图的链接有时会过期。 :)

标签: android android-framelayout cardview


【解决方案1】:

将您的卡片视图放入 AnyLayout 中,如 LinearLayout

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

【讨论】:

  • 非常感谢您的友好回复。它工作得很好。 这工作得很好。再次感谢您。
【解决方案2】:

试试下面的方法:

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

【讨论】:

    【解决方案3】:

    请像这样使用卡片视图

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多