我想定制自己的Android中的ListView像自定义列表视图中的Android
什么,我究竟想要实现我想在每个ListView项和左侧添加这些颜色当然,我想为每个项目使用不同的颜色。我怎样才能做到这一点?
这是我的列表视图是代码:
<RelativeLayout
android:id="@+id/hidden_panel"
android:layout_width="match_parent"
android:layout_marginTop="56dp"
android:layout_height="match_parent"
android:background="@android:color/white"
android:visibility="gone" >
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="500dp" >
</ListView>
<Button
android:id="@+id/button7"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:text="Compute admission chance"
android:textAllCaps="false"
android:background="@drawable/roundshapebtn"
android:layout_below="@id/listView1"
android:layout_centerInParent="true" />
</RelativeLayout>
编辑: 这是我为我的列表视图项:
ListView lv = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.spinner_layout,listRecNames);
lv.setAdapter(adapter);
布局:
<?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="95dp"
android:divider="?android:dividerVertical"
android:showDividers="middle" >
<!-- You can use any view here. Set background "rectangle.xml" drawable to this view.-->
<View
android:layout_width="20dip"
android:layout_height="20dip"
android:background="@drawable/rectangle"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<TextView
android:id="@+id/custom_spinner"
android:textSize="16sp"
android:padding="10dp"
android:textColor="#000"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
但我得到这个错误:
ArrayAdapter requires the resource ID to be a TextView
到目前为止您尝试了什么?你失败了? – Selvin
将该视图添加到您的listview项目的xml文件中。 –
您需要使用CollapsingToolbarLayout和RecyclerView的组合。 –