频道
来源:互联网 发布:windows sever 2003 编辑:程序博客网 时间:2024/06/11 17:07
1
public class MyGridView extends GridView { public MyGridView(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }}
2
public class OtherAdapter extends BaseAdapter { private Context context; public List<String> channelList; private TextView item_text; /** 是否可见 在移动动画完毕之前不可见,动画完毕后可见*/ boolean isVisible = true; /** 要删除的position */ public int remove_position = -1; /** 是否是用户频道 */ private boolean isUser = false; public OtherAdapter(Context context, List<String> channelList , boolean isUser) { this.context = context; this.channelList = channelList; this.isUser = isUser; } @Override public int getCount() { return channelList == null ? 0 : channelList.size(); } @Override public String getItem(int position) { if (channelList != null && channelList.size() != 0) { return channelList.get(position); } return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = LayoutInflater.from(context).inflate(R.layout.adapter_mygridview_item, null); item_text = (TextView) view.findViewById(R.id.text_item); String channel = getItem(position); item_text.setText(channel); if(isUser){ if ((position == 0) || (position == 1)){ item_text.setEnabled(false); } } if (!isVisible && (position == -1 + channelList.size())){ item_text.setText(""); item_text.setSelected(true); item_text.setEnabled(true); } if(remove_position == position){ item_text.setText(""); } return view; } /** 获取频道列表 */ public List<String> getChannnelLst() { return channelList; } /** 添加频道列表 */ public void addItem(String channel) { channelList.add(channel); notifyDataSetChanged(); } /** 设置删除的position */ public void setRemove(int position) { remove_position = position; notifyDataSetChanged(); // notifyDataSetChanged(); } /** 删除频道列表 */ public void remove() { channelList.remove(remove_position); remove_position = -1; notifyDataSetChanged(); } /** 设置频道列表 */ public void setListDate(List<String> list) { channelList = list; } /** 获取是否可见 */ public boolean isVisible() { return isVisible; } /** 设置是否可见 */ public void setVisible(boolean visible) { isVisible = visible; }}
3
public class HomeActivity extends Activity implements AdapterView.OnItemClickListener { private MyGridView mUserGv, mOtherGv; private List<String> mUserList = new ArrayList<>(); private List<String> mOtherList = new ArrayList<>(); private OtherAdapter mUserAdapter, mOtherAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mUserGv = (MyGridView) findViewById(R.id.userGridView); mOtherGv = (MyGridView) findViewById(R.id.otherGridView); Intent intent = getIntent(); ArrayList<String> list = intent.getStringArrayListExtra("list"); for (int i = 0; i < list.size(); i++) { if (i<10){ mUserList.add(list.get(i)); } else if (i>9){ mOtherList.add(list.get(i)); } } initView(); } public void initView() { mUserAdapter = new OtherAdapter(this, mUserList,true); mOtherAdapter = new OtherAdapter(this, mOtherList,false); mUserGv.setAdapter(mUserAdapter); mOtherGv.setAdapter(mOtherAdapter); mUserGv.setOnItemClickListener(this); mOtherGv.setOnItemClickListener(this); } /** *获取点击的Item的对应View, *因为点击的Item已经有了自己归属的父容器MyGridView,所有我们要是有一个ImageView来代替Item移动 * @param view * @return */ private ImageView getView(View view) { view.destroyDrawingCache(); view.setDrawingCacheEnabled(true); Bitmap cache = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); ImageView iv = new ImageView(this); iv.setImageBitmap(cache); return iv; } /** * 获取移动的VIEW,放入对应ViewGroup布局容器 * @param viewGroup * @param view * @param initLocation * @return */ private View getMoveView(ViewGroup viewGroup, View view, int[] initLocation) { int x = initLocation[0]; int y = initLocation[1]; viewGroup.addView(view); LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mLayoutParams.leftMargin = x; mLayoutParams.topMargin = y; view.setLayoutParams(mLayoutParams); return view; } /** * 创建移动的ITEM对应的ViewGroup布局容器 * 用于存放我们移动的View */ private ViewGroup getMoveViewGroup() { //window中最顶层的view ViewGroup moveViewGroup = (ViewGroup) getWindow().getDecorView(); LinearLayout moveLinearLayout = new LinearLayout(this); moveLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); moveViewGroup.addView(moveLinearLayout); return moveLinearLayout; } /** * 点击ITEM移动动画 * * @param moveView * @param startLocation * @param endLocation * @param moveChannel * @param clickGridView */ private void MoveAnim(View moveView, int[] startLocation, int[] endLocation, final String moveChannel, final GridView clickGridView, final boolean isUser) { int[] initLocation = new int[2]; //获取传递过来的VIEW的坐标 moveView.getLocationInWindow(initLocation); //得到要移动的VIEW,并放入对应的容器中 final ViewGroup moveViewGroup = getMoveViewGroup(); final View mMoveView = getMoveView(moveViewGroup, moveView, initLocation); //创建移动动画 TranslateAnimation moveAnimation = new TranslateAnimation( startLocation[0], endLocation[0], startLocation[1], endLocation[1]); moveAnimation.setDuration(300L);//动画时间 //动画配置 AnimationSet moveAnimationSet = new AnimationSet(true); moveAnimationSet.setFillAfter(false);//动画效果执行完毕后,View对象不保留在终止的位置 moveAnimationSet.addAnimation(moveAnimation); mMoveView.startAnimation(moveAnimationSet); moveAnimationSet.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { moveViewGroup.removeView(mMoveView); // 判断点击的是DragGrid还是OtherGridView if (isUser) { mOtherAdapter.setVisible(true); mOtherAdapter.notifyDataSetChanged(); mUserAdapter.remove(); } else { mUserAdapter.setVisible(true); mUserAdapter.notifyDataSetChanged(); mOtherAdapter.remove(); } } }); } @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { switch (parent.getId()) { case R.id.userGridView: //position为 0,1 的不可以进行任何操作 if (position != 0 && position != 1) { final ImageView moveImageView = getView(view); if (moveImageView != null) { TextView newTextView = (TextView) view.findViewById(R.id.text_item); final int[] startLocation = new int[2]; newTextView.getLocationInWindow(startLocation); final String channel = ((OtherAdapter) parent.getAdapter()).getItem(position);//获取点击的频道内容 mOtherAdapter.setVisible(false); //添加到最后一个 mOtherAdapter.addItem(channel); new Handler().postDelayed(new Runnable() { public void run() { try { int[] endLocation = new int[2]; //获取终点的坐标 mOtherGv.getChildAt(mOtherGv.getLastVisiblePosition()).getLocationInWindow(endLocation); MoveAnim(moveImageView, startLocation, endLocation, channel, mUserGv, true); mUserAdapter.setRemove(position); } catch (Exception localException) { } } }, 50L); } } break; case R.id.otherGridView: final ImageView moveImageView = getView(view); if (moveImageView != null) { TextView newTextView = (TextView) view.findViewById(R.id.text_item); final int[] startLocation = new int[2]; newTextView.getLocationInWindow(startLocation); final String channel = ((OtherAdapter) parent.getAdapter()).getItem(position); mUserAdapter.setVisible(false); //添加到最后一个 mUserAdapter.addItem(channel); new Handler().postDelayed(new Runnable() { public void run() { try { int[] endLocation = new int[2]; //获取终点的坐标 mUserGv.getChildAt(mUserGv.getLastVisiblePosition()).getLocationInWindow(endLocation); MoveAnim(moveImageView, startLocation, endLocation, channel, mOtherGv,false); mOtherAdapter.setRemove(position); } catch (Exception localException) { } } }, 50L); } break; default: break; } }}
4
- 列表内容
在 res 下创建一个color文件subscribe_item_text_color<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/subscribe_item_selected_stroke" /> <item android:state_pressed="true" android:color="@color/subscribe_item_text_color_pressed" /> <item android:color="@color/subscribe_item_text_color_normal" /></selector>
- 列表内容
drawable目录下 创建 subscribe_item_bg.xml <?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_selected="true"> <layer-list> <item> <shape> <stroke android:width="1.0dip" android:color="@color/subscribe_item_drag_stroke" android:dashWidth="4.0dip" android:dashGap="2.0dip" /> <solid android:color="@color/subscribe_item_drag_bg" /> </shape> </item> </layer-list> </item> <item android:state_selected="true"> <shape> <stroke android:width="1.0dip" android:color="@color/subscribe_item_selected_stroke" /> <solid android:color="@color/subscribe_item_selected_bg" /> </shape> </item> <item android:state_enabled="false"> <shape> <stroke android:width="0.5dip" android:color="@color/subscribe_item_disabled_stroke" /> <solid android:color="@color/subscribe_item_disabled_bg" /> </shape> </item> <item android:state_pressed="true"> <shape> <stroke android:width="0.5dip" android:color="@color/subscribe_item_pressed_stroke" /> <solid android:color="@color/subscribe_item_pressed_bg" /> </shape> </item> <item> <shape> <stroke android:width="0.5dip" android:color="@color/subscribe_item_normal_stroke" /> <solid android:color="@color/subscribe_item_normal_bg" /> </shape> </item></selector>
- 列表内容
values 下color下 添加 <item name="subscribe_item_text_color_normal" type="color">@color/default_text</item> <color name="subscribe_item_text_color_pressed">#ffb9b9b9</color> <color name="default_text">#ff454545</color> <color name="subscribe_item_text_color_pressed_night">#ff303030</color> <color name="subscribe_item_focused_stroke">#ffd9d9d9</color> <color name="subscribe_item_drag_stroke">#ffd2d2d2</color> <color name="subscribe_item_drag_bg">#fff5f5f5</color> <color name="subscribe_item_drag_stroke_night">#ff464646</color> <color name="subscribe_item_drag_bg_night">#ff252525</color> <color name="subscribe_item_selected_bg">#ffffffff</color> <color name="subscribe_item_selected_stroke">#ffcc3131</color> <color name="subscribe_item_disabled_bg">#ffefefef</color> <color name="subscribe_item_disabled_stroke">#ffd9d9d9</color> <color name="subscribe_item_pressed_bg">#fff9f9f9</color> <color name="subscribe_item_pressed_stroke">#ffcdcdcd</color> <color name="subscribe_item_normal_bg">#fff5f5f5</color> <color name="subscribe_item_normal_stroke">#ffcdcdcd</color> <color name="subscribe_item_focused_bg_night">#ff252525</color> <color name="subscribe_item_focused_stroke_night">#ff464646</color> <color name="subscribe_item_selected_bg_night">#ff252525</color> <color name="subscribe_item_selected_stroke_night">#ffbc494d</color> <color name="subscribe_item_disabled_bg_night">#ff2b2b2b</color>
- 列表内容
- 5 ##
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/subscribe_main_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="14.0dip"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10.0dip" android:layout_marginTop="14.0dip" android:gravity="bottom" android:orientation="horizontal"> <TextView android:id="@+id/my_category_tip_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我的频道" android:textSize="13sp" /> </LinearLayout> <View android:id="@+id/seperate_line" android:layout_width="match_parent" android:layout_height="0.5dp" android:layout_marginBottom="14.0dip" android:layout_marginTop="10dp" android:background="@color/subscribe_item_drag_stroke" /> <com.bawei.myapplication.MyGridView android:id="@+id/userGridView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="14dip" android:layout_marginRight="14dip" android:gravity="center" android:horizontalSpacing="14dip" android:listSelector="@android:color/transparent" android:numColumns="4" android:scrollbars="vertical" android:stretchMode="columnWidth" android:verticalSpacing="14.0px" /> <View android:id="@+id/seperate_line2" android:layout_width="match_parent" android:layout_height="0.5dp" android:layout_marginTop="10dp" android:background="@color/subscribe_item_drag_stroke" /> <TextView android:id="@+id/more_category_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="14.0dip" android:layout_marginLeft="10.0dip" android:layout_marginTop="10dp" android:text="更多频道" android:textSize="13sp" /> <com.bawei.myapplication.MyGridView android:id="@+id/otherGridView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="14dip" android:layout_marginRight="14dip" android:gravity="center" android:horizontalSpacing="14dip" android:listSelector="@android:color/transparent" android:numColumns="4" android:scrollbars="vertical" android:stretchMode="columnWidth" android:verticalSpacing="14.0px" /> </LinearLayout> </ScrollView></LinearLayout>
- 列表内容
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_subscribe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="38.0dip" android:minWidth="72.0dip" > <TextView android:id="@+id/text_item" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/subscribe_item_bg" android:gravity="center" android:minHeight="38.0dip" android:minWidth="72.0dip" android:textColor="@color/subscribe_item_text_color" android:textSize="14.0sp" /> <!-- android:layout_margin="5dip" --> <ImageView android:id="@+id/icon_new" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /></RelativeLayout>
适配器
public class MyAdapter extends BaseAdapter { private Context context; private List<Bean.DataBean.ComicsBean> mlist; private ViewHodler hodler; private ArrayList<String> list=new ArrayList<>(); public MyAdapter(Context context, List<Bean.DataBean.ComicsBean> mlist) { this.context = context; this.mlist = mlist; } @Override public int getCount() { return mlist.size(); } @Override public Object getItem(int position) { return mlist.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView==null){ hodler = new ViewHodler(); convertView=View.inflate(context, R.layout.xlistview_view,null); hodler.type= (TextView) convertView.findViewById(R.id.type); hodler.name=(TextView) convertView.findViewById(R.id.name); hodler.quan=(TextView) convertView.findViewById(R.id.quan); hodler.image=(ImageView) convertView.findViewById(R.id.image_view); hodler.huaju=(TextView) convertView.findViewById(R.id.huaju); convertView.setTag(hodler); }else { hodler= (ViewHodler) convertView.getTag(); } hodler.type.setText(mlist.get(position).getLabel_text()); hodler.name.setText(mlist.get(position).getTopic().getTitle()); hodler.quan.setText(mlist.get(position).getTopic().getUpdate_status()); x.image().bind(hodler.image,mlist.get(position).getCover_image_url()); hodler.huaju.setText(mlist.get(position).getTitle()); //跳转 传值 hodler.quan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, HomeActivity.class); for (int i = 0; i <mlist.size() ; i++) { list.add(mlist.get(i).getLabel_text()); } intent.putStringArrayListExtra("list",list); context.startActivity(intent); list.clear();//清空集合 } }); return convertView; } static class ViewHodler{ TextView type; TextView name; TextView quan; ImageView image; TextView huaju; }}
阅读全文
0 0
- 频道
- 频道
- 频道
- CSDN频道
- 记录频道
- 数据库频道
- 频道认领
- 少儿频道
- 杂物频道
- 频道管理
- 频道管理
- 频道管理
- 频道管理
- 频道管理
- 频道管理
- 频道管理
- 频道管理
- 频道管理
- JDK1.7后的字符串比较
- delphi 数组复制利用CopyMemory 最为完美
- XLua笔记-将lua项目和unity工程放到VS中
- 【Qt 编译】QT 工程文件
- postgresql+pgrouting 最短路线sql (4)
- 频道
- Git忽略规则及.gitignore规则不生效的解决办法
- C# 判断用户是手机访问还是电脑访问
- 测试Shutdown
- jQuery选择器
- CopyFile
- lo4j简介
- 新浪云SAE部署详细图解教程
- 'gbk' codec can't decode byte 0xaf in position 6532: illegal multibyte sequence