Vat*_*rma 15 android android-cardview android-elevation
我有一个布局XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/containor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff6da"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.vats.vatishs.cardviewprogrammatically.MainActivity">
<FrameLayout
android:id="@+id/card"
android:layout_width="220dp"
android:layout_marginTop="10dp"
android:layout_height="wrap_content">
<TextView
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="Hello I am a text View." />
</FrameLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="210dp"
android:background="@drawable/select_delete_chim" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.结果将是框架布局上方的图像视图,但是当我使用下面的xml时,我用CardView替换了框架布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/containor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff6da"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.vats.vatishs.cardviewprogrammatically.MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="220dp"
android:layout_marginTop="10dp"
android:layout_height="wrap_content">
<TextView
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="Hello I am a text View." />
</android.support.v7.widget.CardView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="210dp"
android:background="@drawable/select_delete_chim" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
然后结果将是:CardView背面的ImageView.
任何解决方案?
更重要的是,它可以在棒棒糖前设备上正常工作,但在棒棒糖上它不起作用.
Vat*_*rma 45
CardView的默认高程大于ImageView,因此我们必须在ImageView中添加比CardView高程更高的高程.
例如imageView.setElevation(10);和cardView.setElevation(5);
现在,它在所有设备上运行良好.
小智 6
你可以使用这个属性
app:cardElevation="0dp"
Run Code Online (Sandbox Code Playgroud)
到 XMl 中的 CardView 。
像这样
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardElevation="0dp"
app:cardUseCompatPadding="true">
Run Code Online (Sandbox Code Playgroud)
这将使前面的其他视图CardView
| 归档时间: |
|
| 查看次数: |
12193 次 |
| 最近记录: |