使用android:elevation使TextView消失

时间:2019-04-15 18:25:26

标签: android android-xml android-elevation

我有这个RelativeLayout,只有两个视图。请在下面查看我尝试过的内容:

<RelativeLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/image_view"
        android:layout_centerInParent="true"
        android:background="@drawable/border"
        android:elevation="4dp"/> //Below TextView disappear

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginTop="-48dp"
        android:layout_below="@+id/image_view"/>
</RelativeLayout>

TextView设置了负数layout_marginTop,因此可以在图像上显示它。一切正常,直到我设置了height属性。设置好之后,下面的TextView消失了。如何阻止这种情况发生?

2 个答案:

答案 0 :(得分:0)

解决方案::将String myString = "12+16"; String[] result = myString.split("(?<=[-+*/])|(?=[-+*/])"); System.out.println(Arrays.toString(result)); 添加到布局文件中的TextView中。

android:elevation="5dp"

您可以点击this链接查看<RelativeLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:layout_width="150dp" android:layout_height="150dp" android:id="@+id/image_view" android:layout_centerInParent="true" android:background="@drawable/border" android:elevation="4dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="-48dp" android:layout_below="@+id/image_view" android:elevation="5dp"/> // Add this line </RelativeLayout> 在Android中的工作方式。

答案 1 :(得分:-1)

改为使用CardView。 希望这项工作。

<android.support.v7.widget.CardView
android:layout_gravity="center_horizontal"        
app:cardElevation="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/image_view"
    android:layout_centerInParent="true"
    android:background="@drawable/border"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginTop="-48dp"
    android:layout_below="@+id/image_view"/>
</RelativeLayout>

</android.support.v7.widget.CardView>
相关问题