【发布时间】:2015-07-05 20:48:17
【问题描述】:
我正在扩展 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);
...
}
...
}
这就是结果
谁能帮帮我?
【问题讨论】:
-
如果您有自定义视图,为什么还要使用 CardView?只需将布局传递给 RecyclerView Adapter onCreateViewHolder
-
我不使用 RecyclerView,如果我不使用 cardview,我应该创建一个可绘制的选择器以具有 cardview 样式
标签: java android android-custom-view android-cardview