快遞物流資訊布局,快遞物流資訊
思路:就一個ListView,每個item就是一條物流資訊。然後每個item,分為左和右兩邊,左邊是一個進度條的風格,右邊是物流文字,適配器裡面判斷item,position為0 就設定為綠色,其他position就設定為灰色就行了。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <!-- 左邊 --> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" > <!-- 上面的豎線 --> <View android:id="@+id/view_top_line" android:layout_width="2dp" android:layout_height="15dp" android:background="@color/lightgray" android:layout_gravity="center_horizontal" android:layout_marginTop="-1dp" /> <!-- 圓點 --> <ImageView android:id="@+id/iv_expres_spot" android:layout_width="20dp" android:layout_height="20dp" android:background="@drawable/express_point_old" android:layout_marginBottom="2dp" android:layout_marginTop="2dp" /> <!-- 豎線 --> <View android:layout_width="2dp" android:layout_height="wrap_content" android:background="@color/lightgray" android:layout_gravity="center_horizontal" /> </LinearLayout> <!-- 右邊 --> <LinearLayout android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dp" android:layout_marginTop="17dp" > <TextView android:id="@+id/tv_express_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="asdfasdfasd大事發生的蘇打粉asdfasdfas阿斯蒂芬斯蒂芬阿薩德發達省份撒旦法" android:textColor="@color/gray" android:lineSpacingExtra="2dp" android:textSize="16sp" android:textIsSelectable="true" /> <TextView android:id="@+id/tv_express_time" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/lightgray" android:textSize="12sp" android:text="2016年4月27日 00:27:45" android:layout_marginTop="5dp" android:textIsSelectable="true" android:paddingBottom="10dp" /> <!-- 底部分割線 --> <View android:layout_width="match_parent" android:background="@color/lightgray" android:layout_height="0.5dp" /> </LinearLayout></LinearLayout>
public class MessListAdapter extends BaseAdapter { //allContent就是所有物流資訊的list private List<Content> allContent; private Context context; private LayoutInflater layoutInflater; MessListAdapter(Context context,List<Content> allContent){ this.allContent = allContent; this.context = context; layoutInflater = LayoutInflater.from(context); } @Override public int getCount() { return allContent.size(); } @Override public Object getItem(int position) { return allContent.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null){ holder = new ViewHolder(); convertView = layoutInflater.inflate(R.layout.item_express_data,null); holder.viewTopLine = convertView.findViewById(R.id.view_top_line); holder.ivExpresSpot = (ImageView) convertView.findViewById(R.id.iv_expres_spot); holder.tvExpressText = (TextView) convertView.findViewById(R.id.tv_express_text); holder.tvExpressTime = (TextView) convertView.findViewById(R.id.tv_express_time); //將ViewHolder與convertView進行綁定 convertView.setTag(holder); }else{ holder = (ViewHolder)convertView.getTag(); } Content content = allContent.get(position); //設定資料顏色,防止view 複用,必須每個設定 if(position == 0 ){ //上頂部背景透明,點是灰色,字型是綠色 holder.viewTopLine.setBackgroundColor(Color.TRANSPARENT); holder.ivExpresSpot.setBackgroundResource(R.drawable.express_point_new); holder.tvExpressText.setTextColor(context.getResources().getColor(R.color.mainColor)); holder.tvExpressTime.setTextColor(context.getResources().getColor(R.color.mainColor)); }else{ holder.viewTopLine.setBackgroundColor(context.getResources().getColor(R.color.lightgray)); holder.ivExpresSpot.setBackgroundResource(R.drawable.express_point_old); holder.tvExpressText.setTextColor(context.getResources().getColor(R.color.gray)); holder.tvExpressTime.setTextColor(context.getResources().getColor(R.color.lightgray)); } holder.tvExpressText.setText(content.getContext()); holder.tvExpressTime.setText(content.getTime()); return convertView; } public class ViewHolder{ public View viewTopLine; private ImageView ivExpresSpot; private TextView tvExpressText; private TextView tvExpressTime; }}