温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android开发中使用RecyclerView怎么实现一个时光轴效果

发布时间:2020-11-23 16:57:30 来源:亿速云 阅读:162 作者:Leah 栏目:移动开发

Android开发中使用RecyclerView怎么实现一个时光轴效果?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

如图:

 Android开发中使用RecyclerView怎么实现一个时光轴效果      

activity_main.xml

<&#63;xml version="1.0" encoding="utf-8"&#63;>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity">

  <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never" />

</RelativeLayout>

item.xml

<&#63;xml version="1.0" encoding="utf-8"&#63;>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="8dp"
  android:paddingRight="8dp"
  android:paddingTop="8dp">
  <TextView
    android:id="@+id/item_timeline_time"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginRight="8dp"
    android:layout_marginTop="18dp"
    android:gravity="center_horizontal"
    android:padding="4dp"
    android:textColor="@color/colorAccent"
    android:textSize="16sp"
    android:text="2015-06-08\n09:56"
    />

  <RelativeLayout
    android:id="@+id/item_timeline_icon_layout"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_marginBottom="4dp"
    android:layout_marginRight="8dp"
    android:layout_toRightOf="@id/item_timeline_time">

    <com.timelinedemo.CircleImageView
      android:id="@+id/item_timeline_icon_bg"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:src="@android:color/transparent"
      app:civ_border_width="4dp" />

    <ImageView
      android:id="@+id/item_timeline_icon"
      android:layout_width="24dp"
      android:layout_height="24dp"
      android:layout_centerInParent="true"
      android:scaleType="fitCenter" />

  </RelativeLayout>

  <TextView
    android:id="@+id/item_timeline_content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="18dp"
    android:layout_toRightOf="@id/item_timeline_icon_layout"
    android:text="今日收入"
    android:textColor="@color/colorPrimary"
    android:textSize="15sp" />

  <TextView
    android:id="@+id/item_timeline_money"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/item_timeline_content"
    android:layout_marginTop="8dp"
    android:layout_toRightOf="@id/item_timeline_icon_layout"
    android:text="$ 100"
    android:textColor="@color/colorPrimary"
    android:textSize="22sp" />
  <View
    android:id="@+id/item_timeline_view"
    android:layout_width="2dp"
    android:layout_height="60dp"
    android:layout_alignLeft="@id/item_timeline_icon_layout"
    android:layout_below="@id/item_timeline_icon_layout"
    android:layout_marginLeft="23dp"
    android:background="@color/colorAccent" />
</RelativeLayout>

Activity.Java

public class MainActivity extends AppCompatActivity {

  private RecyclerView recyclerView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initLayout();
  }
  private void initLayout(){
    recyclerView= (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    initData();
  }
  private void initData(){
    List<TimeInfo > list=new ArrayList<>();
    for(int i=0;i<15;i++){
      list.add(new TimeInfo());
    }
    TimelineAdapter mAdapter = new TimelineAdapter(this, list);
    recyclerView.setAdapter(mAdapter);
  }
}

添加依赖库:

compile 'com.android.support:recyclerview-v7:23.0.0'

看完上述内容,你们掌握Android开发中使用RecyclerView怎么实现一个时光轴效果的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI