我有一个扩展CardView的自定义控件。我将其添加到线性布局中,以便可以创建纸牌网格。我没有使用ListView或RecyclerView。
我想在线性布局中的卡片之间设置一个间隙,因此我定义了一个边距。
卡布局使用深色主题。我的应用程序使用默认的材质主题(深色)。我正在Android 6.0.1的Pixel C上进行测试。
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
card_view:cardElevation="5dp"
style="@style/CardView.Dark">
<!-- content here -->
</android.support.v7.widget.CardView>
我将它们添加到这样的列表视图中:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
LinearLayout newLinearLayout = new LinearLayout(this);
newLinearLayout.setLayoutParams(layoutParams);
newLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
mainLayoutContainer.addView(newLinearLayout);
newLinearLayout.addView(myCardLayoutObj);
在CardView中使用布局的类实际上扩展了CardView本身,例如
public class MyCustomWidgetextends CardView{
public MyCustomWidget(Context context) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_card_view_layout, this);
}
我看到的是这个。卡中的内容部分看起来很好..黑色。但是CardView周围的边距/空白是白色的。我如何使它透明化?为什么黑卡主题会这样显示?另外,在这样的深色主题上,阴影会是什么样?
所以我有一个布局文件,其中包括<CardView>
如上所述。我的自定义类夸大了这种布局,扩展了CardView。因此,我在CardView中有一个CardView。“外部”卡片视图(即我的自定义类扩展的视图)从未设置其主题,因此它使用了默认的“浅色”主题。
因为我是通过编程方式创建此小部件的,所以我认为我需要扩展CardView。这是错误的。
前:
public class MyCustomWidget extends CardView
后:
public class MyCustomWidget extends LinearLayout{
public MyCustomWidget(Context context) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_card_view_layout, this);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句