我扩展CardView类,因为我想为列表视图的每一行创建自定义视图。这是我的xml布局
<com.mojiapps.myquran.items.TranslationDownloadItemView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?selectableItemBackground"
android:gravity="right"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3dp"
card_view:cardPreventCornerOverlap="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
...
</com.mojiapps.myquran.items.TranslationDownloadItemView>
这是我的java类
public class TranslationDownloadItemView extends CardView {
public TranslationDownloadItemView(Context context) {
super(context);
init();
}
public TranslationDownloadItemView(Context context, AttributeSet attrs) {
super(context, attrs);
}
private void init() {
LayoutInflater inflater = LayoutInflater.from(getContext());
inflater.inflate(R.layout.translation_type_row, this);
...
}
...
}
这就是结果
有人能帮我吗?
3条答案
按热度按时间nhaq1z211#
我有这个问题设置CardView背景透明的东西。我解决了它设置一个非alpha颜色。
尝试将
android:foreground
设置为不带alpha的值。r7knjye22#
在我的例子中,我通过将白色背景设置为
CardView
来解决它或者您可以将cardElevation设置为0dp,但这将禁用阴影
icomxhvb3#
我知道这是一个老问题,但我想指出一个更简单的方法来膨胀一个孩子的观点(所以经常被忽视)。
而不是:
试试这个:
使用静态View**inflate()**是最干净、最有效的方法;你不需要LayoutInflater。