码迷,mamicode.com
首页 > 移动开发 > 详细

Android小工具

时间:2016-05-07 06:59:28      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

  公司网络烂,自己又不想findview写很多遍,所以自己写了个小工具,自动findview,生成代码到剪贴版.


技术分享



test:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/home_backgroud"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <RelativeLayout
            android:id="@+id/headerLine"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#3d61f3"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/title"
                style="@style/header"
                android:text="儿童保护" >
            </TextView>

            <ImageView
                android:id="@+id/setchild_menu_btn"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="3.0dip"
                android:layout_marginRight="3.0dip"
                android:layout_marginTop="3.0dip"
                android:gravity="center"
                android:src="@drawable/ic_back" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginLeft="@dimen/margin"
            android:layout_marginRight="@dimen/margin"
            android:layout_marginTop="@dimen/margin_top"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="开始时间"
                android:textColor="@color/black"
                android:textSize="@dimen/textsize"
                android:gravity="center_vertical" />

            <EditText
                android:id="@+id/et_childstarttime"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:singleLine="true" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginLeft="@dimen/margin"
            android:layout_marginRight="@dimen/margin"
            android:layout_marginTop="@dimen/margin_top"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="结束时间"
                android:textColor="@color/black"
                android:textSize="@dimen/textsize"
                android:gravity="center_vertical" />

            <EditText
                android:id="@+id/et_childendtime"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:singleLine="true" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginLeft="@dimen/margin"
            android:layout_marginRight="@dimen/margin"
            android:layout_marginTop="@dimen/margin_top"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="性别"
                android:textColor="@color/black"
                android:textSize="@dimen/textsize"
                android:gravity="center_vertical" />

            <EditText
                android:id="@+id/et_childsex"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:hint="男/女"
                android:singleLine="true" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginLeft="@dimen/margin"
            android:layout_marginRight="@dimen/margin"
            android:layout_marginTop="@dimen/margin_top"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:text="周期"
                android:textColor="@color/black"
                android:textSize="@dimen/textsize"
                android:gravity="center_vertical"/>

            <EditText
                android:id="@+id/et_childperiod"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:singleLine="true" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginLeft="@dimen/margin"
            android:layout_marginRight="@dimen/margin"
            android:layout_marginTop="@dimen/margin_top" >

            <Button
                android:id="@+id/setchild_ok"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="确认"
                android:textColor="@color/black"
                android:textSize="@dimen/textsize"
                android:gravity="center"/>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="vertical" >
    </LinearLayout>

</LinearLayout>

生成代码:

 

	<pre name="code" class="java">	private RelativeLayout headerLine;
	private TextView title;
	private ImageView setchild_menu_btn;
	private EditText et_childstarttime;
	private EditText et_childendtime;
	private EditText et_childsex;
	private EditText et_childperiod;
	private Button setchild_ok;



	private void bindview(){
		headerLine=(RelativeLayout) findViewById(R.id.headerLine);
		title=(TextView) findViewById(R.id.title);
		setchild_menu_btn=(ImageView) findViewById(R.id.setchild_menu_btn);
		et_childstarttime=(EditText) findViewById(R.id.et_childstarttime);
		et_childendtime=(EditText) findViewById(R.id.et_childendtime);
		et_childsex=(EditText) findViewById(R.id.et_childsex);
		et_childperiod=(EditText) findViewById(R.id.et_childperiod);
		setchild_ok=(Button) findViewById(R.id.setchild_ok);

	}



详细代码请看http://git.oschina.net/food91/Android-tool-findviewid

Android小工具

标签:

原文地址:http://blog.csdn.net/qq296571277/article/details/51335918

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!