android开发之单选按钮

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ebebeb" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="#2b3134" >

            <ImageButton
                android:id="@+id/infor_back"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="@color/transparent"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:scaleType="centerInside"
                android:src="@drawable/ac0" />

            <View
                android:id="@+id/view_temp"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="8dp"
                android:layout_toRightOf="@id/infor_back"
                android:background="#14191A" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/view_temp"
                android:text="违法停车告知单信息"
                android:textColor="#ffffff"
                android:textSize="18sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="5dp"
            android:background="#ffffff"
            android:clickable="true" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="15dp"
                android:gravity="center"
                android:paddingLeft="5dp"
                android:text="车牌号:"
                android:textColor="#000000"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/plate_number"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="20dp"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:text="5555555"
                android:textColor="#000000"
                android:textSize="18sp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="#ffffff" >

            <TextView
                android:id="@+id/car_cl"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="15dp"
                android:gravity="center"
                android:paddingLeft="5dp"
                android:text="车身颜色:"
                android:textColor="#000000"
                android:textSize="18sp" />

            <EditText
                android:id="@+id/car_color"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="20dp"
                android:layout_toRightOf="@id/car_cl"
                android:cursorVisible="true"
                android:gravity="center_vertical"
                android:hint="请输入车身颜色"
                android:paddingLeft="10dp"
                android:singleLine="true"
                android:textColor="#000000"
                android:textSize="18sp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="192dp"
            android:background="#ffffff"
            android:clickable="true" >

            <TextView
                android:id="@+id/car_type"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="15dp"
                android:gravity="center_horizontal"
                android:paddingLeft="5dp"
                android:paddingTop="15dp"
                android:text="车辆类型:"
                android:textColor="#000000"
                android:textSize="18sp" />

            <com.example.view.FlowRadioGroup
                android:id="@+id/cartype_radio_group"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_toRightOf="@id/car_type" >

                <RadioButton
                    android:id="@+id/big_carriage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="大型客车"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/middle_carriage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="0dp"
                    android:text="中型客车"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/small_carriage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="小型客车"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/big_car"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="大型货车"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/small_car"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="小型货车"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/motor_cycle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="摩托车        "
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/cartype_else"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="其他"
                    android:textColor="#000000"
                    android:textSize="14sp" />
            </com.example.view.FlowRadioGroup>

            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="94dp"
            android:background="#ffffff"
            android:clickable="true" >

            <TextView
                android:id="@+id/plate_number_cl"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="15dp"
                android:gravity="center_horizontal"
                android:paddingLeft="5dp"
                android:paddingTop="15dp"
                android:text="号牌颜色:"
                android:textColor="#000000"
                android:textSize="18sp" />

            <com.example.view.FlowRadioGroup
                android:id="@+id/plate_number_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_toRightOf="@id/plate_number_cl" >

                <RadioButton
                    android:id="@+id/yellow_numb"
                    android:layout_width="33dp"
                    android:layout_height="24dp"
                    android:text="黄色"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/blue_numb"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="蓝色"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/black_numb"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="黑色"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RadioButton
                    android:id="@+id/color_else"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="其他"
                    android:textColor="#000000"
                    android:textSize="14sp" />
            </com.example.view.FlowRadioGroup>

            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true"
        android:background="#2b3134" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/information_change"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_weight="1"
                android:background="@android:color/transparent"
                android:gravity="center"
                android:text="修改"
                android:textColor="@android:color/white"
                android:textSize="20dp" />

            <View
                android:id="@+id/infor_view_temp"
                android:layout_width="4dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:layout_toRightOf="@id/information_change"
                android:background="#14191A" />

            <Button
                android:id="@+id/information_sure"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_weight="1"
                android:background="@android:color/transparent"
                android:gravity="center"
                android:text="确定"
                android:textColor="@android:color/white"
                android:textSize="20dp" />
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>
package com.example.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RadioGroup;

public class FlowRadioGroup extends RadioGroup {

    public FlowRadioGroup(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
        int childCount = getChildCount();
        int x = 0;
        int y = 0;
        int row = 0;

        for (int index = 0; index < childCount; index++) {
            final View child = getChildAt(index);
            if (child.getVisibility() != View.GONE) {
                child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
                // 此处增加onlayout中的换行判断,用于计算所需的高度
                int width = child.getMeasuredWidth();
                int height = child.getMeasuredHeight();
                x += width;
                y = row * height + height;
                if (x > maxWidth) {
                    x = width;
                    row++;
                    y = row * height + height;
                }
            }
        }
        // 设置容器所需的宽度和高度
        setMeasuredDimension(maxWidth, y);

    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        final int childCount = getChildCount();
        int maxWidth = r - l;
        int x = 0;
        int y = 0;
        int row = 0;
        for (int i = 0; i < childCount; i++) {
            final View child = this.getChildAt(i);
            if (child.getVisibility() != View.GONE) {
                int width = child.getMeasuredWidth();
                int height = child.getMeasuredHeight();
                x += width;
                y = row * height + height;
                if (x > maxWidth) {
                    x = width;
                    row++;
                    y = row * height + height;
                }
                child.layout(x - width, y - height, x, y);
            }
        }
    }

}
// 注册单选按钮的监听事件
        cartype_radio_group.setOnCheckedChangeListener(listener1);
        plate_number_group.setOnCheckedChangeListener(listener2);
        car_color = (EditText) findViewById(R.id.car_color);
        back = (ImageButton) findViewById(R.id.infor_back);

    }

    private RadioGroup.OnCheckedChangeListener listener1 = new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == big_carriage.getId()) {
                cartype = big_carriage.getText().toString();
            } else if (checkedId == middle_carriage.getId()) {
                cartype = middle_carriage.getText().toString();
            } else if (checkedId == small_carriage.getId()) {
                cartype = small_carriage.getText().toString();
            } else if (checkedId == big_car.getId()) {
                cartype = big_car.getText().toString();
            } else if (checkedId == small_car.getId()) {
                cartype = small_car.getText().toString();
            } else if (checkedId == motor_cycle.getId()) {
                cartype = motor_cycle.getText().toString();
            } else {
                cartype = color_else.getText().toString();
            }

        }
    };
    private RadioGroup.OnCheckedChangeListener listener2 = new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == yellow_numb.getId()) {
                color_car = yellow_numb.getText().toString();
            } else if (checkedId == blue_numb.getId()) {
                color_car = blue_numb.getText().toString();
            } else if (checkedId == black_numb.getId()) {
                color_car = black_numb.getText().toString();
            } else {
                color_car = yellow_numb.getText().toString();
            }

        }
    };
时间: 2024-07-29 16:45:31

android开发之单选按钮的相关文章

转发:Android开发?用C#!!

转发自 最近偶然在QQ技术群里见到有人提起用C#开发Android,当时我感觉到很诧异:Android不是只能用Java开发吗?何时可以使用C#了?那个群友便告知我:mono. 百度一下吧!搜到了mono的官方网站:http://xamarin.com/(英文网站,看这个够头大的了) 根据我仅有的点英语知识,好得看懂了些:   Mono是用C#和.Net在VS环境下开发多个平台手机应用程序.意思就是说通过Mono,可以开发多个平台的手机应用程序(即iOS和Android).听起来好像不错,但它是

【Android学习】《Android开发视频教程》第一季笔记

视频地址: http://study.163.com/course/courseMain.htm?courseId=207001 课时5    Activity基础概念 1.Android开发技术结构图 2.Android四大组件 Activity(页面).Service(后台运行的服务).Content Provider(数据提供者,向外暴露数据的方法,数据共享).Broadcast Receiver(监听手机发生的一切事情) 课时6    文本框与按钮的使用方法(Activity初步一) 1

Android开发1:基本UI界面设计——布局和组件

前言 啦啦啦~本学期要开始学习Android开发啦~ 博主在开始学习前是完完全全的小白,只有在平时完成老师要求的实验的过程中一步一步学习~从此篇博文起,博主将开始发布Android开发有关的博文,希望能在学习中和各位共同探讨,一起交流,共同进步~ 话不多说,首先进入我们的正题~Android开发一基本UI界面设计——布局和组件(Android Studio的配置安装使用等在以后为各位补上~) 基础知识 Android的组件分为布局和控件.布局,就是让控件在里面按一定的次序排列好的一种组件,本身并

android 开发概述以及相关背景知识

参考链接:http://www.runoob.com/android/android-architecture.html http://www.runoob.com/android/android-application-components.html Android 架构 Android 操作系统是一个软件组件的栈,在架构图中它大致可以分为五个部分和四个主要层. Linux内核 在所有层的最底下是 Linux - 包括大约115个补丁的 Linux 3.6.它提供了基本的系统功能,比如进程管理

android开发常用组件和第三方库(二)

TimLiu-Android 自己总结的Android开源项目及库. github排名 https://github.com/trending, github搜索:https://github.com/search 目录 UI UI 卫星菜单 节选器 下拉刷新 模糊效果 HUD与Toast 进度条 UI其它 动画 网络相关 响应式编程 地图 数据库 图像浏览及处理 视频音频处理 测试及调试 动态更新热更新 消息推送 完整项目 插件 出名框架 其他 好的文章 收集android上开源的酷炫的交互动

Android开发之入口Activity

原文:Android开发之入口Activity Android开发之入口Activity Adnroid App是如何确定入口Activity的? 难道就因为class的类名叫MainActivity,布局文件叫activity_main.xml? 如果这样认为,就大错特错了. 之所以能够确定入口Activity,是因为在应用的清单文件中有所配置,系统会根据应用的清单文件(AndroidManifest.xml)来确立. 如何确立,标志是什么? 我们来看一下清单文件,便一目了然: 对了,系统能够

2062326 齐力锋 实验四《Java面向对象程序设计Android开发》实验报告

北京电子科技学院(BESTI) 实 验 报 告 课程: 程序设计与数据结构  班级: 1623  姓名: 齐力锋 学号: 20162326 成绩: 指导教师: 娄嘉鹏/王志强 实验日期: 2017年5月26日 实验密级:非密级 预习程度: 优良 实验时间: 2 Hours 仪器组次: 必修/选修: 必修 实验序号: 04 实验名称:Java面向对象程序设计Android开发 实验内容 1.Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBI

Android开发系列之SQLite

上篇博客提到过SQLite.它是嵌入式数据库,因为其轻巧但功能强大,被广泛的用于嵌入式设备其中.后来在智能手机.平板流行之后,它作为文件型数据库,差点儿成为了智能设备单机数据库的必选,能够随着安卓app打包到apk文件其中. SQLite的官方站点是http://www.sqlite.org/,能够随意下载,上面也有详尽的文档能够參考,这篇博客重点关注SQLite在Android开发中怎样使用. 在Android开发中.推荐建立一个类继承自SQLiteOpenHelper来创建数据库操作类,比方

Android开发之手把手教你写ButterKnife框架(二)

欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52664112 本文出自:[余志强的博客] 上一篇博客Android开发之手把手教你写ButterKnife框架(一)我们讲了ButterKnife是什么.ButterKnife的作用和功能介绍以及ButterKnife的实现原理. 本篇博客主要讲在android studio中如何使用apt. 一.新建个项目, 然后创建一个module名叫processor 新建m