CardView忽略android:clipChildren =“false”

时间:2015-09-02 14:10:07

标签: android android-cardview margin

我想要一个包含ImageView的CardView,它与CardView的左边界重叠。 我想通过给ImageView一个负余量来做到这一点。 通过设置clipChildren =“false”,这适用于所有其他布局(LinearLayout / RelativeLayout / FrameLayout)。

但是我无法使用CardView。 ImageView将被剪裁,并且不会与CardView重叠。

09-02 11:14:18.692: E/AndroidRuntime(17814): FATAL EXCEPTION: main
09-02 11:14:18.692: E/AndroidRuntime(17814): java.lang.NullPointerException
09-02 11:14:18.692: E/AndroidRuntime(17814):    at com.rs21.hallel.objetos.Adapter_agenda.getChildrenCount(Adapter_agenda.java:150)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(ExpandableListConnector.java:568)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.ExpandableListConnector.access$000(ExpandableListConnector.java:50)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.ExpandableListConnector$MyDataSetObserver.onChanged(ExpandableListConnector.java:862)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.BaseExpandableListAdapter.notifyDataSetChanged(BaseExpandableListAdapter.java:56)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at com.rs21.hallel.objetos.Adapter_agenda$1.onCheckedChanged(Adapter_agenda.java:135)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.CompoundButton.setChecked(CompoundButton.java:137)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.CompoundButton.toggle(CompoundButton.java:92)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.widget.CompoundButton.performClick(CompoundButton.java:104)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.view.View$PerformClick.run(View.java:17229)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.os.Handler.handleCallback(Handler.java:615)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.os.Handler.dispatchMessage(Handler.java:92)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.os.Looper.loop(Looper.java:137)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at android.app.ActivityThread.main(ActivityThread.java:4960)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at java.lang.reflect.Method.invokeNative(Native Method)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at java.lang.reflect.Method.invoke(Method.java:511)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
09-02 11:14:18.692: E/AndroidRuntime(17814):    at dalvik.system.NativeStart.main(Native Method)

4 个答案:

答案 0 :(得分:8)

好的,这似乎只是Android 5+的一个问题,解决方法是设置

cardView.setClipToOutline(false);

来源 - https://www.reddit.com/r/androiddev/comments/2tccge/cant_draw_outside_of_cardview_parent/

答案 1 :(得分:1)

使用param LinearLayout

将其打包在LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false">

<android.support.v7.widget.CardView/>

</LinearLayout>

答案 2 :(得分:0)

添加:

android:clipChildren="false" 

到CardView的祖父视图。

答案 3 :(得分:0)

将此添加到您的 MaterialCardView xml 文件

android:outlineProvider="none"