当前位置: 首页 > news >正文

新手建立网站的步骤广州市企业网站建设平台

新手建立网站的步骤,广州市企业网站建设平台,Wordpress找不到外观选项,影楼招聘在安卓应用中#xff0c;有很多时候需要动态添加View。比如从后台获取商品列表#xff0c;根据商品数量在页面渲染对应数量的条目#xff0c;这时候就需要动态添加View。 1.动态添加View的方法 动态添加View有两种方法#xff1a; 由代码生成子View#xff1a;这种方式…在安卓应用中有很多时候需要动态添加View。比如从后台获取商品列表根据商品数量在页面渲染对应数量的条目这时候就需要动态添加View。 1.动态添加View的方法 动态添加View有两种方法 由代码生成子View这种方式很繁琐布局效果也不直观而且很多属性设置不了也可能是我没找对方法从xml读取布局然后动态设置信息推荐该方式配置xml时可以直接看到效果可设置的参数也更多。 接下来就用代码演示下如何使用这两种方式动态添加View。 注子View也可以写在父View中设置visible为GONE即可在createItem最后添加一行item.setVisibility(View.VISIBLE);。 2. 代码实现 父View布局activity_list.xml ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalScrollViewandroid:layout_widthmatch_parentandroid:layout_height480dpandroid:layout_gravitycenter_horizontal|topandroid:layout_margin10dpLinearLayoutandroid:idid/list_itemsandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationvertical //ScrollViewLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:gravitycenter_horizontalButtonandroid:idid/list_switch_modelandroid:layout_width100dpandroid:layout_height70dpandroid:layout_gravitycenterandroid:layout_marginRight20dpandroid:textSwitch Model /Buttonandroid:idid/list_add_itemandroid:layout_width100dpandroid:layout_height70dpandroid:layout_gravitycenterandroid:layout_marginLeft20dpandroid:textAdd Item //LinearLayout /LinearLayout子View布局activity_item.xml ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentLinearLayoutandroid:idid/itemandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop5dpandroid:layout_marginBottom5dpandroid:orientationhorizontalLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitycenter_verticalandroid:layout_marginLeft10dpandroid:layout_marginRight10dpandroid:gravityright|centerandroid:orientationhorizontalImageViewandroid:idid/item_imgandroid:layout_width48dpandroid:layout_height48dpandroid:layout_marginLeft10dpandroid:layout_marginRight10dpandroid:padding10dpandroid:srcdrawable/common_item //LinearLayoutLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightmatch_parentandroid:layout_gravitycenterandroid:layout_marginLeft10dpandroid:layout_marginRight10dpandroid:gravityleft|centerandroid:orientationverticalTextViewandroid:idid/item_indexandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textindex: item nameandroid:textColorcolor/blackandroid:textSize6pt /TextViewandroid:idid/item_nameandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textname: item nameandroid:textColorcolor/blackandroid:textSize6pt //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:layout_gravitycenter_verticalandroid:layout_marginRight10dpandroid:gravityright|centerandroid:orientationhorizontalImageViewandroid:idid/item_editandroid:layout_width48dpandroid:layout_height48dpandroid:layout_marginRight10dpandroid:padding10dpandroid:srcdrawable/common_edit /ImageViewandroid:idid/item_deleteandroid:layout_width48dpandroid:layout_height48dpandroid:layout_marginRight10dpandroid:padding10dpandroid:srcdrawable/common_delete //LinearLayout/LinearLayout /LinearLayoutactivity类 package org.tao.hetools.activities;import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView;import androidx.activity.ComponentActivity; import androidx.annotation.Nullable;import org.tao.hetools.R; import org.tao.hetools.entities.ItemInfo;import java.util.ArrayList; import java.util.List;public class DynamicViewActivity extends ComponentActivity {private int index 0;private boolean createViewFromXml true;private ListItemInfo itemInfos new ArrayList();private LinearLayout listItemsLayout;Overrideprotected void onCreate(Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_list);listItemsLayout findViewById(R.id.list_items);initButton();initDynamicView();}private void initDynamicView() {if (listItemsLayout null) {return;}listItemsLayout.removeAllViews();for (ItemInfo itemInfo : itemInfos) {listItemsLayout.addView(createViewFromXml ? createViewFromCode(itemInfo) : createViewFromCode(itemInfo));}}private void initButton() {findViewById(R.id.list_add_item).setOnClickListener(view - {if (listItemsLayout null) {return;}ItemInfo itemInfo new ItemInfo(index, name index, R.drawable.common_item);index;itemInfos.add(itemInfo);listItemsLayout.addView(createViewFromXml ? createItem(itemInfo) : createViewFromCode(itemInfo));});findViewById(R.id.list_switch_model).setOnClickListener(view - {itemInfos.clear();listItemsLayout.removeAllViews();createViewFromXml !createViewFromXml;});}/*** 在代码中生成布局作为子view的布局** param itemInfo item信息* return item view*/private View createViewFromCode(ItemInfo itemInfo) {// item开头的图标layoutImageView itemImage new ImageView(this);itemImage.setImageResource(R.drawable.common_item);itemImage.setMaxHeight(136);// 这个高度跟dp的换算需要根据屏幕分辨率重新计算。下同itemImage.setMaxWidth(136);itemImage.setLeft(10);itemImage.setRight(10);itemImage.setPadding(5, 5, 5, 5);itemImage.setAdjustViewBounds(true);LinearLayout imageLayout new LinearLayout(this);imageLayout.setOrientation(LinearLayout.HORIZONTAL);imageLayout.addView(itemImage);// item信息layoutTextView index new TextView(this);index.setText(index: itemInfo.getIndex());index.setTextSize(10);TextView name new TextView(this);name.setText(name: itemInfo.getName());name.setTextSize(10);LinearLayout infoLayout new LinearLayout(this);infoLayout.setOrientation(LinearLayout.VERTICAL);infoLayout.addView(index);infoLayout.addView(name);// 操作layoutImageView edit new ImageView(this);edit.setImageResource(R.drawable.common_edit);edit.setMaxHeight(136);edit.setMaxWidth(136);edit.setAdjustViewBounds(true);ImageView delete new ImageView(this);delete.setImageResource(R.drawable.common_delete);delete.setMaxHeight(136);delete.setMaxWidth(136);delete.setAdjustViewBounds(true);LinearLayout operateLayout new LinearLayout(this);operateLayout.setOrientation(LinearLayout.HORIZONTAL);operateLayout.addView(edit);operateLayout.addView(delete);// 子view的信息LinearLayout layout new LinearLayout(this);layout.setOrientation(LinearLayout.HORIZONTAL);layout.addView(imageLayout);layout.addView(infoLayout);layout.addView(operateLayout);edit.setOnClickListener(view - {// todo 此处处理edit的点击事件Log.i(itemInfoList: , itemInfos.toString());});delete.setOnClickListener(view - {itemInfos.remove(itemInfo);listItemsLayout.removeView(layout);});return layout;}/*** 从xml文件获取布局作为子view的布局** param itemInfo item信息* return item view*/private View createItem(ItemInfo itemInfo) {LinearLayout inflate (LinearLayout) LayoutInflater.from(this).inflate(R.layout.activity_item, null);LinearLayout item inflate.findViewById(R.id.item);((ImageView) item.findViewById(R.id.item_img)).setImageResource(itemInfo.getImageResourceId());((TextView) item.findViewById(R.id.item_index)).setText(index: itemInfo.getIndex());((TextView) item.findViewById(R.id.item_name)).setText(name: itemInfo.getName());item.findViewById(R.id.item_edit).setOnClickListener(view - {// todo 此处处理edit的点击事件Log.i(itemInfoList: , itemInfos.toString());});item.findViewById(R.id.item_delete).setOnClickListener(view - {itemInfos.remove(itemInfo);listItemsLayout.removeView(item);});((ViewGroup) item.getParent()).removeAllViews();return item;} }
http://www.w-s-a.com/news/597169/

相关文章:

  • 四川建设厅网站施工员证查询网站建设行业政策
  • 网站全站出售dw怎么设计网页
  • 合肥网站建设方案服务网站建设推荐郑国华
  • 襄阳网站建设需要多少钱台州网站设计公司网站
  • 东莞专业拍摄做网站照片如何在百度上发布自己的广告
  • 网站建设费 科目做网站建设最好学什么
  • php商城网站建设多少钱深圳市建设
  • 有什么做糕点的视频网站黄岛做网站
  • 做视频课程网站建设一个普通网站需要多少钱
  • 专做化妆品的网站合肥做网站建设公司
  • 唐山企业网站网站建设费计入那个科目
  • 企业网站制作运营彩虹云主机官网
  • 如何建设废品网站如何在阿里云云服务器上搭建网站
  • 如何建立网站后台程序wordpress 后台管理
  • 山东外贸网站建设怎么样wordpress首页左图右文
  • 志丹网站建设wordpress 形式修改
  • 南通seo网站推广费用网站建设就业前景
  • 自适应网站做mip改造浏览器广告投放
  • 网站meta网页描述网站的推广费用
  • 偃师市住房和城乡建设局网站网站个人主页怎么做
  • 做网站要实名认证吗wordpress去掉仪表盘
  • 在哪做网站好Python建网站的步骤
  • 卢松松的网站办公室设计布局
  • 住房城乡建设干部学院网站织梦网站0day漏洞
  • 企业网站seo优帮云手机桌面布局设计软件
  • 无证做音频网站违法吗智能建站加盟电话
  • 鹿泉专业网站建设做网站为什么要建站点
  • 加强网站建设和维护工作新闻大全
  • 红鱼洞水库建设管理局网站左右左布局网站建设
  • 手机网站建设地址做网站公