位置: 编程技术 - 正文

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的正确设置

  • 进项税转出包括什么
  • 费用计入管理费用与销售费用的区别
  • 综合所得预扣预缴表在哪里查
  • 过桥费是多少
  • 工程机械租赁增值税税率很多适用错误应该是9不是13
  • 发票必须用完才可以购买吗
  • 个人独资企业可以投资有限公司吗
  • 银行承兑汇票背书可以拆分
  • 增值税专用发票有效期是多长时间
  • 培训发生的差旅费的会计准则有哪些
  • 企业年金个人所得税最新规定
  • 公司聘请专家的差旅费可以税前扣除吗
  • 承包工程会计账务处理流程
  • 多计提的销售费用冲销
  • 周转材料计入什么账
  • 下列应税项目中,不按次计算征收个人所得税的是
  • 定金不买了可以退吗
  • 车间不生产时折旧怎么算
  • 个人取得的稿酬收入应该如何计算
  • 异地交纳的五险一金可以在个人所得税扣除吗?
  • 企事业单位承包承租经营
  • 增值税普票需要进项吗
  • 跨年度的成本费用发票怎么入账
  • 房租费可以计入研发费用加计扣除吗
  • 实际发生坏账的账务处理分录
  • 小规模固定资产一次性扣除
  • 年初未分配利润计算公式
  • 财管如何区分金额大小
  • 工程机械租赁公司图片
  • 旅游服务业账务处理办法
  • 福利费需要扣税吗
  • 卖废旧物品账务处理
  • php公众号
  • 应收账款未计提坏账能直接核销
  • win10 ltsc版
  • 生产型企业出口外购货物可以退税吗
  • 企业所得税税金及附加包括
  • 工会经费是如何计提的
  • laravel orm使用
  • mvc与mvvm
  • vue项目安装路由
  • erp面试题目100及最佳答案
  • 网络课平台用交税吗
  • 天猫如何不走对公账户
  • python中如何创建文件
  • 帝国cms视频教程
  • mysql的where语句优化
  • 如何保护数据库
  • 小规模劳务派遣公司税率
  • 申请电子发票需要什么条件
  • 教育培训业能享受补贴吗
  • 租车协议要不要报税务机关备案?
  • 基本户收到零余额转款怎么做分录
  • 国外佣金算什么费用比较好
  • 会计中借方和贷方各指什么
  • 固定资产后续支出计入的科目
  • 认证固定资产发票如何入账
  • 进项税有什么相关要求
  • 财经网课 app
  • vs2019连接mysql
  • windows注册表简单应用
  • freebsd12安装
  • 32位操作系统不能玩cf
  • apache版本查看命令
  • dgservice.exe是什么进程
  • win7 win8.1
  • OpwareSE2.exe - OpwareSE2是什么进程 有什么用
  • 索尼笔记本安装软件顺序
  • android开发环境是什么
  • 创建表格在哪里找
  • perl获取文件名
  • cocos2dx schedule
  • vue异步加载第三方库
  • 安全的代码
  • 简述python语言
  • python 举例
  • Android ToolBar 的简单封装
  • 陷阱类过关游戏
  • 为什么python那么难
  • 广告业发票税率是多少 可以抵扣多少
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设