android 时间轴怎么实现的
2017-02-24
展开全部
没什么好说的,直接上代码吧!相信你能看懂
1/apk/res/android"" target="_blank">schemas/apk/res/android"</a> android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <View android:layout_width="1dp" android:layout_height="25dp" android:layout_marginLeft="60dp" android:background="#A6A6A6" /> <ImageView android:id="@+id/left_imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:src="@drawable/medicalcheck2" /> <View android:layout_width="1dp" android:layout_height="25dp" android:layout_marginLeft="60dp" android:background="#A6A6A6" /> </LinearLayout> <LinearLayout android:layout_alignLeft="@id/left" android:layout_width="match_parent" android:layout_height="70dp" android:orientation="vertical" android:gravity="center" android:layout_marginLeft="100dp"> <TextView android:id="@+id/right_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="aaa"/> </LinearLayout> </RelativeLayout>2.图片和文字的model
12345678910111213141516171819202122232425262728293031package com.sdufe.thea.guo.model; public class TimeLineModel { private int imageview; private String text; public int getImageview() { return imageview; } public void setImageview(int imageview) { this.imageview = imageview; } public String getText() { return text; } public void setText(String text) { this.text = text; } public TimeLineModel(int imageview, String text) { super(); this.imageview = imageview; this.text = text; } }3时间轴的适配器
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071package com.sdufe.thea.guo.adapter; import java.util.List; import com.sdufe.thea.guo.R;import com.sdufe.thea.guo.model.TimeLineModel; import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView; public class TimeLineAdapter extends BaseAdapter { Context context; List<TimeLineModel> list; public TimeLineAdapter(Context context, List<TimeLineModel> list) { super(); this.context = context; this.list = list; } @Override public int getCount() { if (list!=null) { return list.size(); } return 0; } @Override public Object getItem(int position) { if (list!=null) { return list.get(position); } return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHold hold; if (convertView==null) { hold=new ViewHold(); convertView=LayoutInflater.from(context).inflate(R.layout.timeline_item, null); convertView.setTag(hold); }else { hold=(ViewHold) convertView.getTag(); } hold.imageView=(ImageView) convertView.findViewById(R.id.left_imageview); hold.show=(TextView) convertView.findViewById(R.id.right_textview); hold.imageView.setImageResource(list.get(position).getImageview()); hold.show.setText(list.get(position).getText()); return convertView; } static class ViewHold{ public TextView show; public ImageView imageView; } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询