Bmob之个人资料设置(三)

比别人多一点执着,你就会创造奇迹。

 

本讲内容:会话页面编写

 

 

 

1、实现轮播广告效果

参考文章  http://blog.csdn.net/liguojin1230/article/details/50158769

 

2、GridView控件编写

     

下面是MyGridView.java文件:

public class MyGridView extends GridView {
	public MyGridView(Context context) {
		super(context);
	}

	public MyGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyGridView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);

		super.onMeasure(widthMeasureSpec, expandSpec);
	}
}


下面是MyGridView.java文件:

public class Adapter_GridView extends BaseAdapter {
	private Context context;
	private int[] data;

	public Adapter_GridView(Context context, int[] data) {
		this.context = context;
		this.data = data;
	}

	public int getCount() {
		return data.length;
	}

	public Object getItem(int arg0) {
		return null;
	}

	public long getItemId(int arg0) {
		return 0;
	}

	public View getView(int position, View currentView, ViewGroup arg2) {
		HolderView holderView = null;
		if (currentView == null) {
			holderView = new HolderView();
			currentView = LayoutInflater.from(context).inflate(
					R.layout.adapter_grid_home, null);
			holderView.iv_pic = (ImageView) currentView
					.findViewById(R.id.iv_adapter_grid_pic);
			currentView.setTag(holderView);
		} else {
			holderView = (HolderView) currentView.getTag();
		}
		holderView.iv_pic.setImageResource(data[position]);

		return currentView;
	}

	public class HolderView {
		private ImageView iv_pic;
	}

}


下面是res/layout/show_view.xml 布局文件:

<?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" >

    <ImageView
        android:id="@+id/iv_adapter_grid_pic"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="center" />

</LinearLayout>


下面是SlideShowView.java主界面文件:

public class Adapter_GridView_hot extends BaseAdapter {
	private Context context;
	private int[] data;

	public Adapter_GridView_hot(Context context, int[] data) {

		this.context = context;
		this.data = data;
	}

	public int getCount() {
		return data.length;
	}

	public Object getItem(int arg0) {
		return null;
	}

	public long getItemId(int arg0) {
		return 0;
	}

	public View getView(int position, View currentView, ViewGroup arg2) {
		HolderView holderView = null;
		if (currentView == null) {
			holderView = new HolderView();
			currentView = LayoutInflater.from(context).inflate(
					R.layout.adapter_grid_hot_home, null);
			holderView.iv_pic = (ImageView) currentView
					.findViewById(R.id.iv_adapter_grid_pic);
			currentView.setTag(holderView);
		} else {
			holderView = (HolderView) currentView.getTag();
		}

		holderView.iv_pic.setImageResource(data[position]);

		return currentView;
	}

	public class HolderView {

		private ImageView iv_pic;

	}

}


下面是res/layout/show_view.xml 布局文件:

<?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" >

    <ImageView
        android:id="@+id/iv_adapter_grid_pic"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/menu_1" />

</LinearLayout>


 

下面是res/layout/fragment_recent.xml 布局文件:

<?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" >

    <include
        android:id="@+id/common_actionbar"
        layout="@layout/include_action_bar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <com.imdemo.view.SlideShowView
                android:id="@+id/viewPager_menu"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_marginBottom="10dp"
                android:background="#00000000" />

            <com.imdemo.view.MyGridView
                android:id="@+id/my_gridview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:horizontalSpacing="10dp"
                android:numColumns="4"
                android:verticalSpacing="10dp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="10dp"
                android:layout_marginTop="10dp"
                android:background="@color/gray" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:orientation="horizontal" >

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.7"
                    android:scaleType="fitXY"
                    android:src="@drawable/menu_1_0" />

                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="@color/gray" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        android:scaleType="fitXY"
                        android:src="@drawable/menu_1_1" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/gray" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1"
                        android:orientation="horizontal" >

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:scaleType="fitXY"
                            android:src="@drawable/menu_1_2" />

                        <View
                            android:layout_width="1dp"
                            android:layout_height="match_parent"
                            android:background="@color/gray" />

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:scaleType="fitXY"
                            android:src="@drawable/menu_1_3" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:background="@color/gray" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:text="特色市场"
                    android:textColor="@color/black"
                    android:textSize="20sp" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:orientation="horizontal" >

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.7"
                        android:scaleType="fitXY"
                        android:src="@drawable/menu_2_1" />

                    <View
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:background="@color/gray" />

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="1.2"
                            android:scaleType="fitXY"
                            android:src="@drawable/menu_2_2" />

                        <View
                            android:layout_width="match_parent"
                            android:layout_height="1dp"
                            android:background="@color/gray" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_weight="1"
                            android:orientation="horizontal" >

                            <ImageView
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="1"
                                android:scaleType="fitXY"
                                android:src="@drawable/menu_2_3" />

                            <View
                                android:layout_width="1dp"
                                android:layout_height="match_parent"
                                android:background="@color/gray" />

                            <ImageView
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="1"
                                android:scaleType="fitXY"
                                android:src="@drawable/menu_2_4" />
                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:background="@color/gray" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:text="热门市场"
                    android:textColor="@color/black"
                    android:textSize="20sp" />

                <com.imdemo.view.MyGridView
                    android:id="@+id/my_gridview_hot"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:horizontalSpacing="5dp"
                    android:numColumns="3"
                    android:verticalSpacing="5dp" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>


 

下面是RecentFragment.java文件:

public class RecentFragment extends BaseFragment implements OnItemClickListener{

	// 分类的九宫格
	private GridView gridView_classify;
	// 热门市场的九宫格
	private GridView my_gridView_hot;
	// 分类的九宫格适配器
	private Adapter_GridView adapter_GridView_classify;
	// 热门市场的九宫格适配器
	private Adapter_GridView_hot adapter_GridView_hot;

	// 分类九宫格的资源文件
	private int[] pic_path_classify = { R.drawable.menu_guide_1,
			R.drawable.menu_guide_2, R.drawable.menu_guide_3,
			R.drawable.menu_guide_4, R.drawable.menu_guide_5,
			R.drawable.menu_guide_6, R.drawable.menu_guide_7,
			R.drawable.menu_guide_8 };
	// 热门市场的资源文件
	private int[] pic_path_hot = { R.drawable.menu_1, R.drawable.menu_2,
			R.drawable.menu_3, R.drawable.menu_4, R.drawable.menu_5,
			R.drawable.menu_6 };

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_recent, container, false);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initVews();
	}

	private void initVews() {
		initTopBarForOnlyTitle("会话");

		gridView_classify = (GridView) findViewById(R.id.my_gridview);
		gridView_classify.setSelector(new ColorDrawable(Color.TRANSPARENT));
		adapter_GridView_classify = new Adapter_GridView(getActivity(),
				pic_path_classify);
		gridView_classify.setAdapter(adapter_GridView_classify);
		gridView_classify.setOnItemClickListener(this); 

		my_gridView_hot = (GridView) findViewById(R.id.my_gridview_hot);
		my_gridView_hot.setSelector(new ColorDrawable(Color.TRANSPARENT));
		adapter_GridView_hot = new Adapter_GridView_hot(getActivity(),
				pic_path_hot);
		my_gridView_hot.setAdapter(adapter_GridView_hot);
		my_gridView_hot.setOnItemClickListener(this);
	}

	/**
	 * gridview点击事件
	 */
	public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
		Toast.makeText(getActivity(), "你点击了"+(position+1), Toast.LENGTH_LONG).show();  
	}

}


 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值