Android 时间线表单

实现效果:可编辑表单,可按时间线增加多个子项,按钮可选择切换。


image.png

代码:
PageForm2Activity.java

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.ab.activity.AbActivity;
import com.ab.util.AbToastUtil;
import com.ab.view.slidingmenu.SlidingMenu;
import com.ab.view.titlebar.AbTitleBar;
import com.andbase.R;
import com.andbase.global.MyApplication;
import com.andbase.patrol.gtDemo.adapter.pagesAdapter.newPagesAdapter.PageForm2Adapter;
import com.andbase.patrol.gtDemo.model.LinkInfoFormDemo;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * author:lmx
 * date:2018/3/19
 * description:form2
 */
public class PageForm2Activity extends AbActivity{

    private MyApplication application;
    private SlidingMenu menu;
    private AbTitleBar mAbTitleBar = null;
    //加载不同布局
    private PageForm2Activity context;
    private ListView listview;
    public List<LinkInfoFormDemo> listInfo = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAbContentView(R.layout.newpages_activity_form2_demo);
        application = (MyApplication)abApplication;
        mAbTitleBar = this.getTitleBar();
        mAbTitleBar.setTitleText("form2");
        mAbTitleBar.setLogo(R.drawable.button_selector_back);
        mAbTitleBar.setTitleBarBackground(R.drawable.top_bg);
        mAbTitleBar.setTitleTextMargin(10, 0, 0, 0);
        mAbTitleBar.setLogoLine(R.drawable.line);
        this.setTitleBarOverlay(true);

        //加载不同布局
        this.listview = (ListView) findViewById(R.id.lvForm1);
        context = this;

        //顶部菜单 保存
        initTitleRightLayout();

        //加载数据
        loadListView();
    }
    /**
     * 加载listView数据
     */
    public void loadListView(){
        try {
            listInfo = new ArrayList<LinkInfoFormDemo>();
            //单选下拉测试数据
            LinkedList<String> data_list = new LinkedList<String>();
            data_list.add("否");
            data_list.add("是");

            LinkInfoFormDemo form1 = new LinkInfoFormDemo();
            form1.setPropertyType(0);
            form1.setTitle1("标题");
            form1.setSingle("单行文本");
            form1.setMore("多行文本");
            form1.setTitle2("标题");
            form1.setRange("取值范围");
            form1.setLabel("标注");
            listInfo.add(form1);

            LinkInfoFormDemo form2 = new LinkInfoFormDemo();
            form2.setPropertyType(0);
            form2.setTitle1("标题");
            form2.setSingle("单行文本");
            form2.setMore("多行文本");
            form2.setTitle2("标题");
            form2.setRange("取值范围");
            form2.setLabel("标注");
            listInfo.add(form2);

        }catch(Exception ex)
        {
            Log.e("JSON Error: ", ex.toString());
        }

        ListView listView = (ListView) findViewById(R.id.lvForm1);
        PageForm2Adapter pageForm2Adapter = new PageForm2Adapter(context,listInfo);
        listView.setAdapter(pageForm2Adapter);
    }

    /**
     * 顶部菜单 保存
     */
    private void initTitleRightLayout() {
        mAbTitleBar.clearRightView();
        View rightSave = mInflater.inflate(R.layout.save_btn_demo, null);
        mAbTitleBar.addRightView(rightSave);
        Button btnSave = (Button) rightSave.findViewById(R.id.saveBtn);
        btnSave.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AbToastUtil.showToast(context,"保存");
            }

        });
    }

}

PageForm2Adapter.java

package com.andbase.patrol.gtDemo.adapter.pagesAdapter.newPagesAdapter;

import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import com.ab.util.AbDialogUtil;
import com.andbase.R;
import com.andbase.patrol.gtDemo.activity.pages.newPages.PageForm2Activity;
import com.andbase.patrol.gtDemo.model.LinkInfoFormDemo;

import java.util.List;

/**
 * author:lmx
 * date:2018/3/19
 * description:form2
 */
public class PageForm2Adapter extends BaseAdapter {

    private PageForm2Activity mContext;
    private List<LinkInfoFormDemo> lists;
    private LayoutInflater layinf;

    public PageForm2Adapter(PageForm2Activity context, List<LinkInfoFormDemo> lists){
        this.mContext = context;
        this.lists = lists;
        layinf = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public int getItemViewType(int position) {
        //根据position返回指定的布局类型,比如0、1,根据这个返回值加载不同布局
        return lists.get(position).getPropertyType();
    }

    @Override
    public int getViewTypeCount() {
        //这里是adapter里有几种布局
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent){

        LinkInfoFormDemo form = lists.get(position);
        ViewHolder viewHolder = null;

        if (form == null) {
            return null;
        }
        if (convertView == null) {
            switch (form.getPropertyType()){
                case 0:
                    convertView = layinf.inflate(R.layout.newpages_form2_list_item_demo, parent, false);
                    //使用减少findView的次数
                    viewHolder = new PageForm2Adapter.ViewHolder();
                    viewHolder.ivLineTop = (ImageView) convertView.findViewById(R.id.ivLineTop);
                    viewHolder.ivLineBottom = (ImageView) convertView.findViewById(R.id.ivLineBottom);
                    viewHolder.tvTitle1 = (TextView) convertView.findViewById(R.id.tvTitle1);
                    viewHolder.tvSingle = (TextView) convertView.findViewById(R.id.tvSingle);
                    viewHolder.tvSelect = (TextView) convertView.findViewById(R.id.tvSelect);
                    viewHolder.tvMore = (TextView) convertView.findViewById(R.id.tvMore);
                    viewHolder.tvTitle2 = (TextView) convertView.findViewById(R.id.tvTitle2);
                    viewHolder.tvRange = (TextView) convertView.findViewById(R.id.tvRange);
                    viewHolder.tvLabel = (TextView) convertView.findViewById(R.id.tvLabel);
                    viewHolder.tvUnit = (TextView) convertView.findViewById(R.id.tvUnit);
                    viewHolder.etSingleValue = (EditText) convertView.findViewById(R.id.etSingleValue);
                    viewHolder.etMoreValue = (EditText) convertView.findViewById(R.id.etMoreValue);
                    viewHolder.etRangeValue = (EditText) convertView.findViewById(R.id.etRangeValue);
                    viewHolder.etRangeValue2 = (EditText) convertView.findViewById(R.id.etRangeValue2);
                    viewHolder.etLabelValue = (EditText) convertView.findViewById(R.id.etLabelValue);
                    viewHolder.btnA = (Button) convertView.findViewById(R.id.btnA);
                    viewHolder.btnB = (Button) convertView.findViewById(R.id.btnB);
                    viewHolder.btnC = (Button) convertView.findViewById(R.id.btnC);
                    //设置标记
                    convertView.setTag(viewHolder);
                    break;
            }
        } else {
            switch (form.getPropertyType()){
                case 0:
                    viewHolder = (PageForm2Adapter.ViewHolder) convertView.getTag();
                    break;
            }
        }
        /**
         * 根据不同布局加载不同数据
         * */
        switch (form.getPropertyType()){
            case 0:
                viewHolder.tvTitle1.setText(form.getTitle1());
                viewHolder.tvSingle.setText(form.getSingle());
                viewHolder.tvMore.setText(form.getMore());
                viewHolder.tvTitle2.setText(form.getTitle2());
                viewHolder.tvRange.setText(form.getRange());
                viewHolder.tvLabel.setText(form.getLabel());
                //按钮点击事件
                final ViewHolder finalViewHolder = viewHolder;
                final ViewHolder finalViewHolder1 = viewHolder;
                final ViewHolder finalViewHolder2 = viewHolder;
                viewHolder.btnA.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        finalViewHolder1.btnA.setBackgroundResource(R.drawable.btn_form2_bg_selected_demo);
                        finalViewHolder1.btnA.setTextColor(Color.WHITE);
                        finalViewHolder.btnB.setBackgroundResource(R.drawable.btn_form2_bg_unselected_demo);
                        finalViewHolder.btnB.setTextColor(Color.parseColor("#b2b2b2"));
                        finalViewHolder2.btnC.setBackgroundResource(R.drawable.btn_form2_bg_unselected_demo);
                        finalViewHolder.btnC.setTextColor(Color.parseColor("#b2b2b2"));
                    }
                });
                viewHolder.btnB.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        finalViewHolder.btnB.setBackgroundResource(R.drawable.btn_form2_bg_selected_demo);
                        finalViewHolder.btnB.setTextColor(Color.WHITE);
                        finalViewHolder1.btnA.setBackgroundResource(R.drawable.btn_form2_bg_unselected_demo);
                        finalViewHolder1.btnA.setTextColor(Color.parseColor("#b2b2b2"));
                        finalViewHolder2.btnC.setBackgroundResource(R.drawable.btn_form2_bg_unselected_demo);
                        finalViewHolder.btnC.setTextColor(Color.parseColor("#b2b2b2"));
                    }
                });
                viewHolder.btnC.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View v) {
                        finalViewHolder1.btnC.setBackgroundResource(R.drawable.btn_form2_bg_selected_demo);
                        finalViewHolder1.btnC.setTextColor(Color.WHITE);
                        finalViewHolder.btnB.setBackgroundResource(R.drawable.btn_form2_bg_unselected_demo);
                        finalViewHolder.btnB.setTextColor(Color.parseColor("#b2b2b2"));
                        finalViewHolder2.btnA.setBackgroundResource(R.drawable.btn_form2_bg_unselected_demo);
                        finalViewHolder.btnA.setTextColor(Color.parseColor("#b2b2b2"));
                    }
                });
                break;
        }
        //隐藏第一个item时间线的上方线和最后一个item的下方线
        switch (position){
            case 0:
                viewHolder.ivLineTop.setBackgroundColor(Color.TRANSPARENT);
                break;
            case 1:
                viewHolder.ivLineBottom.setBackgroundColor(Color.TRANSPARENT);
                break;
            default:
                break;
        }

        return convertView;
    }

    /**
     * ViewLinkDetailHolder类
     */
    static class ViewHolder {
        ImageView ivLineTop;//时间线
        ImageView ivLineBottom;//时间线
        TextView tvTitle1;//标题一
        TextView tvSingle;//单行文本
        EditText etSingleValue;//单行文本
        TextView tvSelect;//选择类别
        Button btnA;//选择类别
        Button btnB;//选择类别
        Button btnC;//选择类别
        TextView tvMore;//多行文本
        EditText etMoreValue;//多行文本
        TextView tvTitle2;//标题2
        TextView tvRange;//取值范围
        EditText etRangeValue;//取值范围
        EditText etRangeValue2;//取值范围
        TextView tvLabel;//标注
        EditText etLabelValue;//标注
        TextView tvUnit;//单位
    }

}

newpages_activity_form2_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@color/gray_white">

    <!-- 列表项 -->
    <ListView
        android:id="@+id/lvForm1"
        android:divider="@null"
        android:dividerHeight="@null"
        android:scrollbars="none"
        android:listSelector="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:fadingEdge="none"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="55dip" />

</RelativeLayout>

LinkInfoFormDemo


image.png

newpages_form2_list_item_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <!-- 第一列 时间线 -->
    <LinearLayout
        android:layout_width="0dip"
        android:layout_weight="0.1"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/ivLineTop"
            android:layout_width="@dimen/history_ellist_line_width"
            android:layout_height="@dimen/form2_line_h"
            android:layout_marginLeft="@dimen/history_ellist_line_margin_left"
            android:orientation="vertical"
            android:background="@color/el_list_left_line_color" />

        <ImageView
            android:id="@+id/ivLineImg"
            android:layout_width="@dimen/history_ellist_group_time"
            android:layout_height="@dimen/history_ellist_group_time"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/history_ellist_group_time_margin"
            android:src="@drawable/history_expand_top_point"
            android:orientation="vertical"/>

        <ImageView
            android:id="@+id/ivLineBottom"
            android:layout_width="@dimen/history_ellist_line_width"
            android:layout_height="match_parent"
            android:layout_marginLeft="@dimen/history_ellist_line_margin_left"
            android:orientation="vertical"
            android:background="@color/el_list_left_line_color" />

    </LinearLayout>

    <!-- 第二列 三角 -->
    <LinearLayout
        android:layout_width="0dip"
        android:layout_weight="0.05"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/ivLineImg1"
            android:layout_width="@dimen/history_ellist_group_time"
            android:layout_height="@dimen/history_ellist_group_time"
            android:layout_centerVertical="true"
            android:layout_marginTop="@dimen/form2_line_h"
            android:src="@drawable/line_img"
            android:orientation="vertical"/>

    </LinearLayout>

    <!-- 第三列 信息名称 -->
    <LinearLayout
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/form1_ll_right"
        android:layout_marginTop="@dimen/form1_ll_top"
        android:layout_marginBottom="@dimen/form2_ll_bottom"
        android:orientation="vertical"
        android:background="@drawable/form1_item_bg_demo">

        <!-- 标题 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_rl_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <TextView
                android:id="@+id/tvTitle1"
                android:layout_width="@dimen/link_rl_tv_w"
                android:layout_height="@dimen/link_rl_tv_h"
                android:gravity="fill_vertical"
                android:text="标题"
                android:textColor="@color/title_text_color"
                android:textSize="@dimen/table_body" />

        </LinearLayout>

        <View android:layout_width="match_parent"
            android:layout_height="@dimen/link_line_h"
            android:layerType="software"
            android:background="@drawable/btn_form2_line_bg_demo"/>

        <!-- 单行文本 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/form2_item_h"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <TextView
                    android:id="@+id/tvSingle"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="fill_vertical"
                    android:text="单行文本"
                    android:textColor="@color/title_text_color"
                    android:textSize="@dimen/table_body" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="3"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <EditText
                    android:id="@+id/etSingleValue"
                    android:background="@color/new_bg_color"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/form2_item_h"
                    android:paddingLeft="@dimen/form2_et_padding"
                    android:gravity="fill_vertical"
                    android:textSize="@dimen/table_body"
                    android:textColor="@color/project_word_color"
                    android:hint="@string/placeholder" />

            </LinearLayout>

        </LinearLayout>

        <!-- 选择类别 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/form2_item_h"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <TextView
                    android:id="@+id/tvSelect"
                    android:layout_width="@dimen/link_rl_tv_w"
                    android:layout_height="match_parent"
                    android:gravity="fill_vertical"
                    android:text="选择类别"
                    android:textColor="@color/title_text_color"
                    android:textSize="@dimen/table_body" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="3"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="@dimen/form2_ll_height"
                    android:layout_marginTop="@dimen/form2_ll_top"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/btnA"
                        android:layout_width="0dip"
                        android:layout_weight="1"
                        android:layout_height="match_parent"
                        android:background="@drawable/btn_form2_bg_selected_demo"
                        android:text="A类"
                        android:gravity="center"
                        android:textColor="@color/white"
                        android:textSize="@dimen/table_body" />

                    <TextView
                        android:layout_width="0dip"
                        android:layout_weight="0.15"
                        android:layout_height="match_parent"/>

                    <Button
                        android:id="@+id/btnB"
                        android:layout_width="0dip"
                        android:layout_weight="1"
                        android:layout_height="match_parent"
                        android:background="@drawable/btn_form2_bg_unselected_demo"
                        android:text="B类"
                        android:gravity="center"
                        android:textColor="@color/details_fix_text_color"
                        android:textSize="@dimen/table_body" />

                    <TextView
                        android:layout_width="0dip"
                        android:layout_weight="0.15"
                        android:layout_height="match_parent"/>

                    <Button
                        android:id="@+id/btnC"
                        android:layout_width="0dip"
                        android:layout_weight="1"
                        android:layout_height="match_parent"
                        android:background="@drawable/btn_form2_bg_unselected_demo"
                        android:text="C类"
                        android:gravity="center"
                        android:textColor="@color/details_fix_text_color"
                        android:textSize="@dimen/table_body" />

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

        <!-- 多行文本 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/form2_item_h2"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <TextView
                    android:id="@+id/tvMore"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="fill_vertical"
                    android:text="多行文本"
                    android:textColor="@color/title_text_color"
                    android:textSize="@dimen/table_body" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="3"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h2">

                <EditText
                    android:id="@+id/etMoreValue"
                    android:background="@color/new_bg_color"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="top"
                    android:paddingTop="@dimen/form2_et_padding"
                    android:paddingLeft="@dimen/form2_et_padding"
                    android:textSize="@dimen/table_body"
                    android:textColor="@color/project_word_color"
                    android:hint="@string/placeholder" />

            </LinearLayout>

        </LinearLayout>

        <View android:layout_width="match_parent"
            android:layout_height="@dimen/link_line_h"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layerType="software"
            android:background="@drawable/btn_form2_line_bg_demo"/>

        <!-- 标题 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_rl_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <TextView
                android:id="@+id/tvTitle2"
                android:layout_width="@dimen/link_rl_tv_w"
                android:layout_height="@dimen/link_rl_tv_h"
                android:gravity="fill_vertical"
                android:text="标题"
                android:textColor="@color/title_text_color"
                android:textSize="@dimen/table_body" />

        </LinearLayout>

        <View android:layout_width="match_parent"
            android:layout_height="@dimen/link_line_h"
            android:layerType="software"
            android:background="@drawable/btn_form2_line_bg_demo"/>

        <!-- 取值范围 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/form2_item_h"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <TextView
                    android:id="@+id/tvRange"
                    android:layout_width="@dimen/link_rl_tv_w"
                    android:layout_height="match_parent"
                    android:gravity="fill_vertical"
                    android:text="取值范围"
                    android:textColor="@color/title_text_color"
                    android:textSize="@dimen/table_body" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="3"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="@dimen/form2_ll_height"
                    android:layout_marginTop="@dimen/form2_ll_top"
                    android:orientation="horizontal">

                    <EditText
                        android:id="@+id/etRangeValue"
                        android:background="@color/new_bg_color"
                        android:layout_width="0dip"
                        android:layout_weight="1"
                        android:layout_height="match_parent"
                        android:paddingLeft="@dimen/form2_et_padding"
                        android:gravity="fill_vertical"
                        android:textSize="@dimen/table_body"
                        android:textColor="@color/project_word_color"
                        android:hint="@string/placeholder" />

                    <TextView
                        android:layout_width="0dip"
                        android:layout_weight="0.4"
                        android:layout_height="match_parent"
                        android:gravity="center"
                        android:text="~"
                        android:textColor="@color/title_text_color"/>

                    <EditText
                        android:id="@+id/etRangeValue2"
                        android:background="@color/new_bg_color"
                        android:layout_width="0dip"
                        android:layout_weight="1"
                        android:layout_height="match_parent"
                        android:paddingLeft="@dimen/form2_et_padding"
                        android:gravity="fill_vertical"
                        android:textSize="@dimen/table_body"
                        android:textColor="@color/project_word_color"
                        android:hint="@string/placeholder" />

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

        <!-- 标注 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/form2_item_h"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <TextView
                    android:id="@+id/tvLabel"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="fill_vertical"
                    android:text="标注"
                    android:textColor="@color/title_text_color"
                    android:textSize="@dimen/table_body" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_weight="3"
                android:orientation="vertical"
                android:layout_height="@dimen/form2_item_h">

                <EditText
                    android:id="@+id/etLabelValue"
                    android:background="@color/new_bg_color"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/form2_item_h"
                    android:paddingLeft="@dimen/form2_et_padding"
                    android:gravity="fill_vertical"
                    android:textSize="@dimen/table_body"
                    android:textColor="@color/project_word_color"
                    android:hint="@string/placeholder" />

            </LinearLayout>

        </LinearLayout>

        <!-- 单位 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/form2_item_h"
            android:orientation="horizontal"
            android:layout_marginTop="@dimen/form2_title_top"
            android:layout_marginLeft="@dimen/form2_title_left"
            android:layout_marginRight="@dimen/form2_title_right">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="right">

                <TextView
                    android:id="@+id/tvUnit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right"
                    android:text="*单位为千米"
                    android:textColor="@color/pages_btn_do_color"
                    android:textSize="@dimen/tb_body" />

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

btn_form2_bg_selected_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 按钮正常的时候的背景 -->
<!-- shape的默认形状是rectangle,还有oval(椭圆),line(线),ring(圆环)-->

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 矩形的圆角弧度 -->
    <corners android:radius="15dp" />
    <!-- 矩形的填充色 -->
    <solid android:color="#33ccc7" />

    <!-- 边界线为实线 -->
    <stroke
        android:width="1dp"
        android:color="#33ccc7" />
</shape>

btn_form2_bg_unselected_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 按钮正常的时候的背景 -->
<!-- shape的默认形状是rectangle,还有oval(椭圆),line(线),ring(圆环)-->

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 矩形的圆角弧度 -->
    <corners android:radius="15dp" />
    <!-- 矩形的填充色 -->
    <solid android:color="#FFF" />

    <!-- 边界线为实线 -->
    <stroke
        android:width="1dp"
        android:color="#c7c7c7" />
</shape>

虚线是设置:View里需要加上android:layerType="software"

 <View android:layout_width="match_parent"
            android:layout_height="@dimen/link_line_h"
            android:layerType="software"
            android:background="@drawable/btn_form2_line_bg_demo"/>

btn_form2_line_bg_demo.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <stroke
        android:dashGap="2dp"
        android:dashWidth="2dp"
        android:width="0.5dp"
        android:color="#e1e1e1" />
</shape>

dimens.xml

 <!-- form1 -->
    <dimen name="form1_ll_left">10dip</dimen>
    <dimen name="form1_ll_right">10dip</dimen>
    <dimen name="form1_ll_bottom">20dip</dimen>
    <dimen name="form1_ll_top">15dip</dimen>
    <dimen name="form1_rl_top">20dip</dimen>
    <dimen name="form1_sp_top">2dip</dimen>
    <dimen name="form1_sp_right">20dip</dimen>
    <dimen name="form1_img_w">12dip</dimen>
    <dimen name="form1_img_h">16dip</dimen>
    <dimen name="form1_img_top">12dip</dimen>
    <dimen name="form1_img_right">15dip</dimen>
    <dimen name="form1_fg_top">-356dip</dimen>
    <dimen name="form1_btn_w">150dip</dimen>
    <dimen name="form1_btn_padding">5dip</dimen>

    <!-- form2 -->
    <dimen name="form2_rl_top">5dip</dimen>
    <dimen name="form2_line_h">30dip</dimen>
    <dimen name="form2_ll_bottom">10dip</dimen>
    <dimen name="form2_ll_height">25dip</dimen>
    <dimen name="form2_ll_top">2.5dip</dimen>
    <dimen name="form2_title_left">10dip</dimen>
    <dimen name="form2_title_right">10dip</dimen>
    <dimen name="form2_title_top">10dip</dimen>
    <dimen name="form2_item_h">30dip</dimen>
    <dimen name="form2_item_h2">60dip</dimen>
    <dimen name="form2_et_padding">5dip</dimen>

完。


image.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271

推荐阅读更多精彩内容

  • 记得刚开始学Android时,看着自己完全用系统控件写出的不忍直视的界面,对于如何做出不一样的按钮,让它们在不同状...
    biloba阅读 1,626评论 1 11
  • 财报是反应一家公司收支盈亏和现金流数据最为详细和客观的一手资料,对于股票投资来说,必须掌握阅读财报的方法,才能从一...
    马天亮阅读 321评论 0 0
  • 首先,我已经订阅了李笑来的《通往财富自由之路》的专栏,每日学习,虽然最近学习的没有这么深入了,但是每天的文章肯定是...
    知乐行阅读 1,081评论 0 0
  • 立秋 荷叶碧宽珠露浅 云烟雨思秋意浓 山叠风险峡径上 夕下暮色一天长 晓云 秦月汉山酒煮剑 晓日残...
    可顿阅读 168评论 0 0
  • “WOOP”方法,是几个英文单词的缩写。从梦想到现实,一共分四步 —— Wish。你想要干什么。比如说你想要一个好...
    Zc_Hwong阅读 778评论 0 0