【问题标题】:How do I place my ImageButton infront of my TextView with elevation?如何将图像按钮放置在具有高度的 TextView 前面?
【发布时间】:2019-01-14 13:35:21
【问题描述】:

我正在向我的应用程序添加一个对话框,我想将我的退出/关闭 ImageButton 放在我的 TextView 上,该 TextView 具有圆角和白色背景的自定义背景,但 ImageButton 一直停留在 TextView 后面。

After Building In Design View

    <android.support.constraint.ConstraintLayout 
    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:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_edittext">

    <TextView
            android:id="@+id/tCarparkName"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginStart="24dp"
            android:layout_marginTop="96dp"
            android:layout_marginEnd="24dp"
            android:background="@drawable/round_edittext"
            android:elevation="4dp"
            android:fontFamily="sans-serif-condensed"
            android:gravity="center"
            android:text="Parkhausname"      
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/a" />

    <ImageButton
            android:id="@+id/ibClose"
            style="@style/Widget.AppCompat.ImageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/a"
            android:layout_alignParentEnd="true"
            android:layout_marginTop="107dp"
            android:layout_marginEnd="48dp"
            android:background="#00000000"
            android:cropToPadding="false"
            android:visibility="visible"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_close" />

</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 你能直观地解释一下吗?你想要达到的目标
  • 检查我上传的图片以获得更好的理解。
  • 也提供您的完整布局文件...
  • 我添加了我的布局谢谢!
  • 第一张图片是您的预期输出吗?

标签: android xml textview imagebutton


【解决方案1】:

因为您在 TextView 上设置了 elevation。尝试在您的 ImageButton 上也设置 translationZelevation

android:translationZ="5dp"android:elevation="5dp"

【讨论】:

  • 就这么简单!谢谢。
  • 如果它对您有帮助,请接受它作为答案,快乐编码:)
【解决方案2】:

android:elevation="5dp"

这为您的布局提供了高程

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-27
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 2016-07-27
    相关资源
    最近更新 更多