Android知识点六:自定义分享菜单
来源:互联网 发布:古天乐捐学校知乎 编辑:程序博客网 时间:2024/06/07 13:21
首先布局:activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center_horizontal"> <Button android:id="@+id/btn_click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="10dip" android:background="@drawable/btn_black_selector" android:focusable="false" android:text="点击" android:textColor="@color/white" android:textSize="18sp" /> <RelativeLayout android:id="@+id/myRelativeLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:background="@drawable/popup_bg_black" android:gravity="bottom|center_horizontal" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:background="@drawable/popup_bg_page" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingBottom="10dip" android:paddingTop="15dip" android:text="选择分享方式" android:textColor="@color/white" android:textSize="16sp" /> <com.tbkj.common.widget.GridViewInScrowView android:id="@+id/sharetype_grid" android:layout_width="match_parent" android:layout_height="wrap_content" android:listSelector="#00000000" android:numColumns="3" > </com.tbkj.common.widget.GridViewInScrowView> <Button android:id="@+id/cancel_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="10dip" android:background="@drawable/btn_black_selector" android:focusable="false" android:text="取消" android:textColor="@color/white" android:textSize="18sp" /> </LinearLayout> </RelativeLayout></RelativeLayout>
自定义控件GridViewInScrowView继承GridView
public class GridViewInScrowView extends GridView {public GridViewInScrowView(Context context) {super(context);}public GridViewInScrowView(Context context, AttributeSet attrs) {super(context, attrs);}public GridViewInScrowView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}@Overridepublic void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);super.onMeasure(widthMeasureSpec, expandSpec);}}
MainActivity.java
public class MainActivity extends Activity implements OnClickListener, OnItemClickListener {public static final String SinaWeiBo = "SinaWeibo";public static final String TencentWeiBo = "TencentWeibo";public static final String Wechat = "Wechat";public static final String WechatMoments = "WechatMoments";private GridViewInScrowView mShareView;private List<Map<String, Object>> data;private Button mButton, cButton;private RelativeLayout myRelativeLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);ShareSDK.initSDK(this);InitView();InitListener();InitData();}void InitView() {mButton = (Button) findViewById(R.id.btn_click);cButton = (Button) findViewById(R.id.cancel_btn);myRelativeLayout = (RelativeLayout) findViewById(R.id.myRelativeLayout);mShareView = (GridViewInScrowView) findViewById(R.id.sharetype_grid);}void InitListener() {mButton.setOnClickListener(this);cButton.setOnClickListener(this);}void InitData() {}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.btn_click:myRelativeLayout.setVisibility(View.VISIBLE);initGridView();break;case R.id.cancel_btn:myRelativeLayout.setVisibility(View.GONE);break;default:break;}}@SuppressWarnings("serial")private void initGridView() {data = new ArrayList<Map<String, Object>>();Map<String, Object> map = new HashMap<String, Object>() {{put("image", R.drawable.ico_sina);put("text", "新浪微博");put("plantform", SinaWeiBo);}};data.add(map);map = new HashMap<String, Object>() {{put("image", R.drawable.ico_microletter);put("text", "微信好友");put("plantform", Wechat);}};data.add(map);map = new HashMap<String, Object>() {{put("image", R.drawable.ico_weibo);put("text", "腾讯微博");put("plantform", TencentWeiBo);}};data.add(map);map = new HashMap<String, Object>() {{put("image", R.drawable.ico_microletter_friend);put("text", "微信朋友圈");put("plantform", WechatMoments);}};data.add(map);SimpleAdapter mAdapter = new SimpleAdapter(this, data, R.layout.shelf_good_details_share_item, new String[] { "image", "text" }, new int[] { R.id.item_img, R.id.item_text });mShareView.setAdapter(mAdapter);}@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {Map<String, Object> map = data.get(position);String mPlantform = map.get("plantform").toString();if (mPlantform.equals(TencentWeiBo)) {Platform platform = ShareSDK.getPlatform(MainActivity.this, TencentWeiBo);} else if (mPlantform.equals(MainActivity.SinaWeiBo)) {Platform platform = ShareSDK.getPlatform(MainActivity.this, SinaWeiBo);} else if (mPlantform.equals(MainActivity.Wechat)) {Platform platform = ShareSDK.getPlatform(MainActivity.this, Wechat);return;} else if (mPlantform.equals(MainActivity.WechatMoments)) {Platform platform = ShareSDK.getPlatform(MainActivity.this, WechatMoments);return;}}}
0 0
- Android知识点六:自定义分享菜单
- Android知识点之菜单
- Android面试知识点分享
- Android知识点整理(六)
- android自定义控件知识点
- android 自定义View知识点
- (六)制作自定义效果按钮菜单
- Android实现自定义菜单
- 自定义Android菜单背景
- 自定义Android菜单背景
- 自定义Android菜单背景
- 自定义Android菜单背景
- 自定义Android菜单背景
- android 中自定义菜单
- Android 自定义菜单
- android控件-自定义菜单
- Android 自定义菜单
- Android 自定义菜单
- 【转载】hmac_sha1.c源码, C语言中的HMAC_SHA1加密方法
- 判断网络状态及当前是什么网络
- Linux下MySQL5.6.15-忘记root密码-重置
- git的分支管理
- loadrunner脚本录制为空的解决方法
- Android知识点六:自定义分享菜单
- hibernate简单多对一实例
- 我对透明的理解
- Apache+Tomcat+mod_jk实现集群和负载均衡问题解决
- MYSQL 之 on duplicate key update
- soft ap && wifi client
- shell 有用的
- logcat 不输出的解决方案
- JAVA正则表达式 Pattern 和 Matcher