我有一个扩展CardView的自定义控件。我将它添加到线性布局中,以便我可以创建一个网格。我没有使用ListView或RecyclerView。黑色主题周围的白色边框CardViews
我想在线性布局内的卡片之间建立一个间隙,所以我定义了一个边距。
卡片布局使用黑暗的主题。我的应用程序使用默认材质主题(黑暗)。我正在测试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周围的空白/空白是白色的。我如何才能让它变得透明,为什么黑卡主题会以这种方式表现出来?而且,这样的黑暗主题会是什么样的影子?
你有刚刚试过'newLinearLayout'的背景属性设置为你想要颜色? – NoChinDeluxe
这样做似乎没有任何效果。这只是cardlayout周围的边缘是白色的,而不是线性布局本身。 –