Android通过代码编写界面布局

这段代码创建了一个FrameLayout,然后在其中添加了一个LinearLayout。LinearLayout设置为垂直方向,包含两个TextView和一个ImageView。TextView显示运单信息和扫描状态,ImageView根据条件显示不同图标。此外,还设置了点击监听器和布局参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android.widget.FrameLayout frameLayout = new android.widget.FrameLayout(this);
                android.widget.FrameLayout.LayoutParams layoutParamsForFrameLayout = new android.widget.FrameLayout.LayoutParams(android.widget.FrameLayout.LayoutParams.MATCH_PARENT, android.widget.FrameLayout.LayoutParams.WRAP_CONTENT);
                frameLayout.setLayoutParams(layoutParamsForFrameLayout);
                frameLayout.setBackgroundColor(android.graphics.Color.LTGRAY);
                android.widget.LinearLayout linearLayout = new android.widget.LinearLayout(this);
                linearLayout.setId(index);
                linearLayout.setTag(waybillDO.getWaybillNum());
                linearLayout.setOnClickListener(this);
                linearLayout.setOrientation(android.widget.LinearLayout.VERTICAL);
                android.widget.LinearLayout.LayoutParams layoutParams = new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
                //linearLayout.setDividerPadding(dip2px(this, 1));
                //android.content.res.Resources resources = getResources();
                //linearLayout.setDividerDrawable(resources.getDrawable(R.drawable.linear_layout_divider));
                layoutParams.setMargins(dip2px(this, 0), dip2px(this, 1), dip2px(this, 0), dip2px(this, 1));
                //linearLayout.setPadding(dip2px(this, 0), dip2px(this, 1), dip2px(this, 0), dip2px(this, 1));
                linearLayout.setBackgroundColor(android.graphics.Color.WHITE);
                linearLayout.setLayoutParams(layoutParams);
                android.widget.TextView textViewWaybillNum = new android.widget.TextView(this);
                android.widget.LinearLayout.LayoutParams layoutParamsForTextView = new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
                layoutParamsForTextView.setMargins(dip2px(this, 10), dip2px(this, 4), dip2px(this, 10), dip2px(this, 0));
                android.widget.LinearLayout.LayoutParams layoutParamsForSummary = new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
                layoutParamsForSummary.setMargins(dip2px(this, 10), dip2px(this, 0), dip2px(this, 10), dip2px(this, 4));
                textViewWaybillNum.setLayoutParams(layoutParamsForTextView);
                java.sql.Timestamp timestamp = waybillDO.getWaybillReceiptDate();
                java.util.Date date = new java.util.Date(timestamp.getTime());
                java.lang.String waybillReceiptDate = dateFormat.format(date);
                java.lang.String leftTopText = waybillDO.getWaybillNum() + "   出貨日期:" + waybillReceiptDate;
                textViewWaybillNum.setText(leftTopText);
                linearLayout.addView(textViewWaybillNum);
                android.widget.TextView textViewWaybillScanSummary = new android.widget.TextView(this);
                textViewWaybillScanSummary.setLayoutParams(layoutParamsForSummary);
                java.lang.String leftBottomText = sSum + "   " + sScanSum + " " + sTakeApartScanCount;
                android.widget.ImageView imageView = new android.widget.ImageView(this);
                if (sum == doneScan) {
                    imageView.setImageResource(R.drawable.ic_baseline_check_circle_24);
                } else {
                    imageView.setImageResource(R.drawable.ic_baseline_circle_24);
                }
                textViewWaybillScanSummary.setText(leftBottomText);
                textViewWaybillScanSummary.setTypeface(android.graphics.Typeface.defaultFromStyle(android.graphics.Typeface.BOLD));
                textViewWaybillScanSummary.setTextSize(16.0f);
                linearLayout.addView(textViewWaybillScanSummary);
                frameLayout.addView(linearLayout);

                android.widget.LinearLayout linearLayoutForImageAndDelete = new android.widget.LinearLayout(this);
                linearLayoutForImageAndDelete.setOrientation(android.widget.LinearLayout.HORIZONTAL);

                android.widget.TextView textViewForDelete = new android.widget.TextView(this);
                textViewForDelete.setText("刪除");
                textViewForDelete.setOnClickListener(this);
                textViewForDelete.setTag(waybillDO.getWaybillNum());
                linearLayoutForImageAndDelete.addView(imageView, 0);
                linearLayoutForImageAndDelete.addView(textViewForDelete, 1);

                android.widget.FrameLayout.LayoutParams layoutParamsForDelete = new android.widget.FrameLayout.LayoutParams(android.widget.FrameLayout.LayoutParams.WRAP_CONTENT, android.widget.FrameLayout.LayoutParams.WRAP_CONTENT);
                layoutParamsForDelete.gravity = android.view.Gravity.END | android.view.Gravity.CENTER_VERTICAL;
                layoutParamsForDelete.rightMargin = dip2px(this, 10);

                frameLayout.addView(linearLayoutForImageAndDelete, layoutParamsForDelete);
                accordingToDriverDeliveryScanAdapter.addHeaderView(frameLayout, index);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值