我是 android 开发的新手,我正在使用 Big Nerd Ranch 指南来帮助我学习 android 开发。我正在通过数组适配器使用列表,我想自定义列表的外观。
我希望我的列表视图也看起来像卡片样式的 UI,但到目前为止我尝试过的一切都阻止了我这样做。当用户深入列表时,我能够获得事件的卡片样式 UI,并且我已在下面粘贴了该代码。但我无法让列表看起来像卡片式 UI
这是看起来像卡片样式 UI 的事件的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:divider="#00000000"
android:dividerHeight="25dip"
android:paddingTop="25dp"
android:paddingLeft="16.0dp"
android:paddingRight="16.0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:clipToPadding="false"
android:background="@drawable/card"
>
<TextView android:id="@+id/event_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:textSize="30dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/category_label"
android:textColor="#808080"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
style="?android:listSeparatorTextViewStyle"
/>
<TextView android:id="@+id/header1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#808080"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
style="?android:listSeparatorTextViewStyle"
/>
<TextView android:id="@+id/header2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
<Button android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:color="#EEEEEE"
/>
</LinearLayout>
我正在使用 simple_list_item_1 的源代码(所以我可以在必要时使用代码),然后我使用这个 xml 来定义列表中的每个项目:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/card"
android:layout_marginLeft="45dp" >
<ImageView android:id="@+id/calendar_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentRight="true"
android:enabled="false"
android:focusable="false"
android:padding="4dp"/>
<TextView
android:id="@+id/crime_list_item_titleTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/calendar_arrow"
android:paddingTop="9dp"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:text="Crime title"/>
"
</RelativeLayout>
这是我的适配器的代码:
private class CrimeAdapter extends ArrayAdapter<Crime> {
public CrimeAdapter(ArrayList<Crime> crimes) {
super(getActivity(), R.layout.list_layout, crimes);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// if we weren't given a view, inflate one
if (null == convertView) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.list_item_crime, null);
// R.layout.list_item_crime is the same as R.android.simple_list_item1 its just the source code so if I need to change it I can
}
如何让我的列表视图看起来像事件?