位置: 编程技术 - 正文

Android自定义动态布局 — 多图片上传(记录一下,以后可能会用到)(安卓自定义动态壁纸)

编辑:rootadmin

推荐整理分享Android自定义动态布局 — 多图片上传(记录一下,以后可能会用到)(安卓自定义动态壁纸),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:android 自定义动画的实现,android 自定义,android 自定义drawable,android 自定义动画的实现,Android自定义动画,android 自定义actionbar,android 自定义actionbar,android 自定义,内容如对您有帮助,希望把文章链接给更多的朋友!

Android自定义动态布局 — 多图片上传

本文介绍Android中动态布局添加图片,多图片上传。

项目中效果图:

技术点:

1.动态添加&#;局中的线条和添加图片的&#;号

2.多张图片异步上传

Android自定义动态布局 — 多图片上传(记录一下,以后可能会用到)(安卓自定义动态壁纸)

首先来看一下布局文件:

[html] view plaincopyprint?<LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f2f2f2" > <LinearLayout android:id="@&#;id/layout_CONTENT" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f2f2f2" android:orientation="vertical" android:padding="5dp" > <!-- 布局由程序动态生成 --> <LinearLayout android:id="@&#;id/layout_container" android:layout_width="dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="5dp" android:background="#cbcbcb" android:orientation="vertical" android:padding="0.2px" /> <TextView android:id="@&#;id/text_no_data" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="dp" android:text="@string/text_picture_upload" android:textSize="dp" /> </LinearLayout> </LinearLayout> 布局很简单,主要是id为layout_container的一个LinearLayout作为父布局。

横向的线条和纵向的线条布局也很简单:

[html] view plaincopyprint?<View xmlns:android=" android:layout_width="match_parent" android:layout_height="1px" android:background="#cbcbcb" /> [html] view plaincopyprint?<View xmlns:android=" android:layout_width="1px" android:layout_height="match_parent" android:background="#cbcbcb" />

下面是动态生成布局的实现方式:

[java] view plaincopyprint?private void initUI() { setContentView(R.layout.activity_main); //setTitle(R.string.button_service_upload_picture); //showBackwardView(R.string.button_backward, true); //showForwardView(R.string.button_upload,true); //最顶层父布局 mLayout = (ViewGroup) findViewById(R.id.layout_container); final int count = 9; //9&#; final int rowCount = (count &#; 2) / 3; for (int i = 0; i < rowCount; i&#;&#;) { if (i != 0) { //加载横向布局线条 View.inflate(this, R.layout.layout_line_horizonal, mLayout); } //创建布局对象,设置按下颜色 final LinearLayout linearLayout = new LinearLayout(this); linearLayout.setBackgroundResource(R.drawable.row_selector); for (int j = 0; j < 3; j&#;&#;) { if (j != 0) { //加载内层纵向布局线条 View.inflate(this, R.layout.layout_line_vertical, linearLayout); } ImageButton imageButton = new ImageButton(this); imageButton.setBackgroundResource(R.drawable.row_selector); imageButton.setTag(TAG); imageButton.setOnClickListener(this); imageButton.setEnabled(false); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f); //添加到linearLayout布局中 linearLayout.addView(imageButton, layoutParams); //将imageButton对象添加到列表 mImageButtonList.add(imageButton); } DisplayManager manager = DisplayManager.getInstance(); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, manager.dipToPixel()); //将View添加到总父布局 mLayout.addView(linearLayout, layoutParams); } //外层设置ImageButton属性 final ImageButton currentImageButton = mImageButtonList.get(mCurrent); currentImageButton.setImageResource(R.drawable.ic_add_picture); currentImageButton.setScaleType(ScaleType.CENTER); currentImageButton.setEnabled(true); }

图片上传功能:

[java] view plaincopyprint?private class UploadPictureTask extends AsyncTask<List<String>, Integer, String> { /* (non-Javadoc) * @see android.os.AsyncTask#doInBackground(Params[]) */ @Override protected String doInBackground(List<String>... params) { final List<String> pictureList = params[0]; for (int i = 0, len = pictureList.size(); i < len; i&#;&#;) { final File file = new File(pictureList.get(i)); //final String response = ApacheHttpUtils.post(mUrlPrefix &#; "/upload", new File[] {file}); // 解析,存储 //final UploadInfo upload = new UploadParser().parse(response).getData(); /*if (upload != null) { final String url = upload.getUrl(); if (url != null) { mPictureUrlList.add(url); } }*/ publishProgress(i); } return null; } /* (non-Javadoc) * @see android.os.AsyncTask#onProgressUpdate(Progress[]) */ @Override protected void onProgressUpdate(Integer... values) { } /* (non-Javadoc) * @see android.os.AsyncTask#onPostExecute(java.lang.Object) */ @Override protected void onPostExecute(String result) { //addPictures(); super.onPostExecute(result); } } 注:类中声明了三个列表去保存之前所操作的记录[java] view plaincopyprint?mImageButtonList = new ArrayList<ImageButton>(); mPicturePathList = new ArrayList<String>(); mPictureUrlList = new ArrayList<String>();

关于细节大家感兴趣的下载源码学习吧。

欢迎下载源码:

ImageView的android:maxHeight,android:minHeight的正确设置 在layout文件中,设置IamgeView的最大(最小)高度(宽度)时,需要同时设置android:adjustViewBounds=true,这样设置才会生效。在代码中设置时,需要setAdjustViewB

android draglistview中拖动异常显示,无法移动到原先位置 这几天在网上找了draglistview可拖动的列表组件,写demo时发现列表在同方向拖动时没有问题,但在拖动中改变方向,如先向上后向下这样就会出现移动到

Android 自定义ListView 实现下拉刷新 上拉加载功能 效果图思考Listview是viewGroup的子类,它本身提供了方法addHeaderView(Viewview),addFooterView(Viewview)去添加头布局和底布局,所以我们只要监听它的onTouchEv

标签: 安卓自定义动态壁纸

本文链接地址:https://www.jiuchutong.com/biancheng/384218.html 转载请保留说明!

上一篇:onInterceptTouchEvent onTouchEvent 的坑 坑死了

下一篇:ImageView的android:maxHeight,android:minHeight的正确设置

  • 实际发的工资跟个人所得税不一样
  • 红冲的发票能不能取消
  • 年终奖可以不计入年总收入吗
  • 制造费用月末不可能有余额
  • 税务局个人开发票流程
  • 关税的记税依据
  • 机动车销售发票可以跨年抵扣吗
  • 未认证的进项也就是库存
  • 出口抵减内销产品应纳税额年终结转
  • 财务报表层次重大错报风险增大了认定层次
  • 营改增后接受实物投资是否需要缴纳增值税?
  • 工程结算与工程施工
  • 出差补贴是否缴纳个人所得税 北京
  • 股东投资款印花税多少
  • 会议费报销注意事项
  • 怎么查询发票是否已认证
  • 应交增值税会计科目
  • 零申报做账怎么做
  • 延期收款利息如何算
  • 内帐应收应付款坏账年末怎么处理?
  • 把u盘变成光盘模式
  • 企业给学校捐款的申请怎么写
  • thinkphp 3.2.3 getshell
  • win10应用商店下载微信
  • 如何在WIN10系统安装IE浏览器
  • 已抵扣的进项税额红冲的账怎么做
  • 来料加工报废产品合同
  • PHP:ftp_get_option()的用法_FTP函数
  • excel2019冻结
  • 应对怯场的方法
  • 便秘怎么办 女性
  • 支付货款怎么做凭证
  • 固定资产非正常损失
  • 所得税季报资产总额怎么算
  • 总结js中常用的字符
  • 无形资产评估增值可以入账吗
  • db2diag命令
  • 在职工教育经费包括哪些
  • 工会筹备金不缴可以吗
  • 员工工资费用
  • 预算会计年末怎么结账
  • 被投资企业清算,长期股权投资处理
  • 怎么把python代码发给别人运行
  • 未分配利润用于扩大再生产
  • 电子章打印不来
  • 利润表反映了什么能力
  • 个体商户个人所得税怎么算
  • 投资性房地产在建期间需要摊销吗
  • 固定资产盘点怎么做
  • 税金及附加里面包含什么
  • 社保可以直接计入费用吗
  • 新会计准则其他收益核算内容
  • 营利性幼儿园是什么意思
  • 其他收益期末余额
  • 财政拨款的事业单位工资
  • 成本费用总额包括营业外支出吗
  • 银行存款账面余额是企业还是银行
  • 执行企业会计准则和小企业会计准则的区别
  • 注册资本可以是欧元吗
  • 企业对于发出的货物
  • 普通发票如何抵扣税
  • 如何在境外银行开户
  • centos7修改mtu
  • mysql怎么把列变成行
  • linux tcpping
  • win7 32位中文语言包
  • linux内核模块命令
  • win7开机无法连接所有网络驱动器
  • linux filezilla使用教程
  • linux常用命令chmod的使用
  • NGUI的UIScrollview的优化
  • js导入图片
  • webpack-loader
  • perl变量后拼接字符串
  • shell 单引号中引用变量
  • 北京地税电话咨询
  • 北京医保网上服务大厅
  • 个体户定额怎么查询
  • 房产税可以抵扣增值税吗
  • 区里的地税局局长是谁
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设