Android--HorizontalListView实现横向滑动

原理:继承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
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值