学习笔记 第三章 常用控件

3.2.1TextView
      对齐方式           android:gravity = "center"
      指定文字大小    android:textSize="24sp"
      指定文字颜色     android:textColor="#ff0f"

3.2.2Button
     系统会对所有Button中的英文字母进行大小写转换,可以使用
      android:textAllCaps = "false"来禁用这一默认特性

为Button 的点击事件注册一个监听器
   1.使用匿名类
     first = (Button) findViewById(R.id.StartFirst);        
      first.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               FirstActivity.actionStart(MainActivity.this);
            }
        });

2.实现接口

public class MainActivity extends BaseActivity implements View.OnClickListener {
Button first,second;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        first = (Button) findViewById(R.id.StartFirst);
        second = (Button) findViewById(R.id.StartSecond);
        first.setOnClickListener(this);
        second.setOnClickListener(this);
   
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.StartFirst:
                FirstActivity.actionStart(MainActivity.this);
                break;
            case R.id.StartSecond: {
                String mydata = "test";
                SecondActivity.actionStart(MainActivity.this, mydata);
            }
                break;
            default:
                break;
        }
    }
}
3.2.3EditText
  在输入框中显示一些提示性的文字  android:hint="Something here"
  指定EditText的最大行数   android:maxLines ="2"  这样当输入的内容超过两行时,文本就会向上滚动而 EditText不会再继续拉伸
  获取 EditText中输入的内容
      editText = (EditText) findViewById(R.id.edittext);
        String inputEdit = editText.getText().toString();

3.2.4ImageView
    android:src属性给ImageView指定一张图片
android:src="@drawable/apple_pic"

通过代码更改ImageView的图片

        imageView = (ImageView) findViewById(R.id.imag);
        imageView.setImageResource(R.drawable.banana_pic);
3.3.4百分比布局
      在LinearLayout,RelativeLayout,FrameLayout中只有LinearLayout支持使用layout_weight属性来实现按比例指定控件大小的功能


按照书上的写导入依赖会出错
解决方法:在sdk下的这个路径去看自己的百分比布局库的版本号
D:\Androidsdk\sdk\extras\android\m2repository\com\android\support\appcompat-v7


添加依赖就可以了  另外添加的这个版本号不能比support:appcompat-v7的这个版本号低

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:percent:25.3.1'
}

布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout
    xmlns:android ="http://schemas.android.com/apk/res/android"
    xmlns:app ="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <Button
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="left|top"
        app:layout_heightPercent="20%"
        app:layout_widthPercent ="40%"
        android:textColor="#00f"
        android:text="height:20%.width:40%"
        />
<Button
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_widthPercent="60%"
    app:layout_heightPercent="80%"
    android:textColor="#ff0"
    android:layout_gravity="bottom|right"
    android:text="height:80%.width:60%"
    />
</android.support.percent.PercentFrameLayout>

注意要定义一个app的命名空间,这样才能使用百分比布局的自定义属性

 xmlns:app ="http://schemas.android.com/apk/res-auto"
还有注意宽,高百分比属性都是app:前缀 而不是android: 


在手机上的误差像素好像太高了一点,中间缝隙好大.......不知道是不是因为大屏
对照大神的代码发现好像是因为背景的原因

用PercentRelativeLayout 布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
    xmlns:android ="http://schemas.android.com/apk/res/android"
    xmlns:app ="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <Button
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:id="@+id/center"
        android:layout_centerInParent="true"
        android:textColor="#00f"
        android:text="center 20% 20%"
        android:textAllCaps="false"
        app:layout_heightPercent="20%"
        app:layout_widthPercent ="20%"
        />
<Button
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_toLeftOf="@id/center"
    android:layout_above="@id/center"
    android:textAllCaps="false"
    android:text="height:40%.width:40%"
    android:textColor="#ff0"
    app:layout_widthPercent="40%"
    app:layout_heightPercent="40%"
    />
<Button
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="height:40%.width:40%"
    android:textAllCaps="false"
    android:textColor="#f0f"
    app:layout_widthPercent="40%"
    app:layout_heightPercent="40%"
    />
</android.support.percent.PercentRelativeLayout>

添加android:background测试

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
    xmlns:android ="http://schemas.android.com/apk/res/android"
    xmlns:app ="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <Button
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:id="@+id/center"
        android:layout_centerInParent="true"
        android:textColor="#00f"
        android:text="center 20% 20%"
        android:textAllCaps="false"
        app:layout_heightPercent="20%"
        app:layout_widthPercent ="20%"
        android:background="#000"
        />
    <Button
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_toLeftOf="@id/center"
        android:layout_above="@id/center"
        android:textAllCaps="false"
        android:text="height:40%.width:40%"
        android:textColor="#ff0"
        app:layout_widthPercent="40%"
        app:layout_heightPercent="40%"
        android:background="#000"
        />
    <Button
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="height:40%.width:40%"
        android:textAllCaps="false"
        android:textColor="#f0f"
        app:layout_widthPercent="40%"
        app:layout_heightPercent="40%"
        android:background="#000"
        />
</android.support.percent.PercentRelativeLayout>


果然没有缝隙了


源码 https://github.com/onlyfelony/PresentLayou


本项目是一个基于SSM(Spring+SpringMVC+MyBatis)后端框架与Vue.js前端框架开发的疫情居家办公系统。该系统旨在为居家办公的员工提供一个高效、便捷的工作环境,同时帮助企业更好地管理远程工作流程。项目包含了完整的数据库设计、前后端代码实现以及详细的文档说明,非常适合计算机相关专业的毕设学生和需要进行项目实战练习的Java学习者。 系统的核心功能包括用户管理、任务分配、进度跟踪、文件共享和在线沟通等。用户管理模块允许管理员创建和管理用户账户,分配不同的权限。任务分配模块使项目经理能够轻松地分配任务给团队成员,并设置截止日期。进度跟踪模块允许员工实时更新他们的工作状态,确保项目按计划进行。文件共享模块提供了一个安全的平台,让团队成员可以共享和协作处理文档。在线沟通模块则支持即时消息和视频会议,以增强团队之间的沟通效率。 技术栈方面,后端采用了Spring框架来管理业务逻辑,SpringMVC用于构建Web应用程序,MyBatis作为ORM框架简化数据库操作。前端则使用Vue.js来实现动态用户界面,搭配Vue Router进行页面导航,以及Vuex进行状态管理。数据库选用MySQL,确保数据的安全性和可靠性。 该项目不仅提供了一个完整的技术实现示例,还为开发者留下了扩展和改进的空间,可以根据实际需求添加新功能或优化现有功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值