如何设置填充为Android的大号cardview部件

编程入门 行业动态 更新时间:2024-10-12 05:48:00
本文介绍了如何设置填充为Android的大号cardview部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是安卓以下属性来和android:paddingTop设置填充新cardview小部件,但它不工作。我可以设置页边距为所有cardview作为一种解决方法内部的控制,但,这是一个痛苦,如果有太多的控制。如何设置填充新cardview小部件?非常感谢......

< android.support.v7.widget.CardView     的xmlns:card_view =htt​​p://schemas.android/apk/res-auto     机器人:ID =@ + ID / card_view     机器人:layout_gravity =中心     机器人:layout_width =match_parent     机器人:layout_height =200dp     机器人:以下属性来=20dp     机器人:paddingRight =@扪/ activity_horizo​​ntal_margin     机器人:paddingTop =20dp     机器人:paddingBottom会=@扪/ activity_vertical_margin     card_view:cardCornerRadius =2DP>     <的TextView         机器人:ID =@ + ID / info_text         机器人:layout_width =match_parent         机器人:layout_height =WRAP_CONTENT         机器人:文本=您好!世界/> < /android.support.v7.widget.CardView>

解决方案

CardView到L preVIEW之前使用RoundRectDrawableWithShadow绘制背景,这将覆盖Drawable.getPadding()来添加阴影填充。该视图的背景被通过code充气后,将覆盖在XML中指定任何填充设置。

您有两种选择:设置填充在运行时使用View.setPadding(),并小心调整阴影,或将所有的布局,指定填充内(但只有前L- preVIEW!) 。后者的选择是最安全的。

< android.support.v7.widget.CardView     的xmlns:card_view =htt​​p://schemas.android/apk/res-auto     机器人:ID =@ + ID / card_view     机器人:layout_gravity =中心     机器人:layout_width =match_parent     机器人:layout_height =200dp     card_view:cardCornerRadius =2DP>     <的FrameLayout         机器人:以下属性来=20dp         机器人:paddingRight =@扪/ activity_horizo​​ntal_margin         机器人:paddingTop =20dp         机器人:paddingBottom会=@扪/ activity_vertical_margin>         <的TextView             机器人:ID =@ + ID / info_text             机器人:layout_width =match_parent             机器人:layout_height =WRAP_CONTENT             机器人:文本=您好!世界/>     < /的FrameLayout> < /android.support.v7.widget.CardView>

I'm using android:paddingLeft and android:paddingTop to set the padding for the new cardview widget but it doesn't work. I can set the margin for all the controls inside the cardview as a workaround but that's a pain if there are too many controls. How to set padding for the new cardview widget? Thanks very much...

<android.support.v7.widget.CardView xmlns:card_view="schemas.android/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="200dp" android:paddingLeft="20dp" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="20dp" android:paddingBottom="@dimen/activity_vertical_margin" card_view:cardCornerRadius="2dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!"/> </android.support.v7.widget.CardView>

解决方案

CardView prior to L-preview uses RoundRectDrawableWithShadow to draw its background, which overrides Drawable.getPadding() to add shadow padding. The view background gets set via code after inflation, which overrides any padding specified in XML.

You have two options: set padding at run time using View.setPadding() and be careful to adjust for the shadows (but only prior to L-preview!), or place everything inside a layout that specifies padding. The latter option is safest.

<android.support.v7.widget.CardView xmlns:card_view="schemas.android/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="200dp" card_view:cardCornerRadius="2dp"> <FrameLayout android:paddingLeft="20dp" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="20dp" android:paddingBottom="@dimen/activity_vertical_margin"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!"/> </FrameLayout> </android.support.v7.widget.CardView>

更多推荐

如何设置填充为Android的大号cardview部件

本文发布于:2023-11-29 14:00:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大号   部件   如何设置   Android   cardview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!