原理:继承AdapterView<ListAdapter>构造的HorizontalListView
效果图:
下面看源码:
这是Activity的布局文件:activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/height40px"
android:orientation="horizontal">
<Spinner
android:id="@+id/sp_year"
android:layout_width="@dimen/width75px"
android:layout_height="match_parent"
android:background="@drawable/shape_drop_down_normal"
/>
<View
android:layout_width="@dimen/width1px"
android:layout_height="match_parent"
android:background="#E1E1E1"
/>
<view.HorizontalListView
android:id="@+id/hl_month"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</view.HorizontalListView>
</LinearLayout>
横向listview的每个item的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tv_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#404040"
android:layout_marginLeft="@dimen/width22px"
android:text="1月"
android:textSize="@dimen/width14px"
android:layout_marginTop="@dimen/height11px"
android:background="@drawable/month_selector"
/>
</LinearLayout>
month_seltctor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape>
<corners android:radius="10dp" />
<solid android:color="#159AF6" />
</shape>
</item>
<item>
<shape>
<corners android:radius="10dp" />
<solid android:color="#ffffff" />
</shape>
</item>
</selector>
主程序:MainActivity.java
public class meterRateActivity extends Activity {
private final static String TAG = meterRateActivity.class.getName();
private meterrateAdapter mMeterrateAdapter;
private HorizontalListViewAdapter hListViewAdapter;
private View olderSelectView = null;
@BindView(R.id.iv_return)
ImageView ivReturn;
@BindView(R.id.sp_year)
Spinner spYear;
@BindView(R.id.tv_total)
TextView tvTotal;
@BindView(R.id.tv_reality)
TextView tvReality;
@BindView(R.id.tv_incomplete)
TextView tvIncomplete;
@BindView(R.id.tv_rate)
TextView tvRate;
@BindView(R.id.rv_workrate)
RecyclerView rvWorkrate;
@BindView(R.id.hl_month)
Horizon