Android基本控件复习笔记(一)

短暂的暑假已经结束了,假期培训正式开始。

Androidmanifest.XML 清单文件

es  资源文件

Drawable  颜色改变

Layout   布局的文件setContentView(R.layout.activity_main);

Menu  微信三个点

Mipmap  图片

<activityandroid:name=".LoginActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

从哪先启动。

<uses-permissionandroid:name="android.permission.INTERNET"/>

网络权限

1.RelativeLayout相对布局

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

    tools:context="com.example.jreduch01.LoginActivity">
<TextView
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/tv"
    android:textSize="20sp"
    android:textColor="@color/colorAccent"
    android:text="基本控件复习"
    android:background="#ff0"
    android:gravity="center"
    />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/et"
        android:hint="@string/hint_user"
        android:drawableLeft="@mipmap/ic_launcher"
        android:layout_below="@+id/tv"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/et_pwd"
        android:hint="@string/hint_pwd"
        android:layout_below="@+id/et"
        android:inputType="textPassword"
        android:imeOptions="actionGo"
        android:drawableLeft="@mipmap/ic_launcher"
        />
    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/rg"
        android:layout_below="@+id/et_pwd">
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb1"
            android:checked="true"
            android:text="男"
            />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb2"
            android:text="女"
            />
    </RadioGroup>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ch1"
        android:text="记住密码"
        android:layout_below="@+id/rg"
        />
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ch2"
        android:text="自动登录"
        android:layout_below="@+id/rg"
        android:layout_toRightOf="@+id/ch1"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ch1"
        android:orientation="horizontal"

        android:gravity="center"
        android:id="@+id/li"
        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bt1"
            android:text="登陆"
            android:layout_weight="1"

            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bt2"
            android:text="注册"
            android:layout_toRightOf="@+id/bt1"
            android:layout_weight="1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bt3"
            android:text="重置"
            android:onClick="reSet"
            android:layout_toRightOf="@+id/bt1"
            android:layout_weight="1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bt4"
            android:text="退出"
            android:layout_toRightOf="@+id/bt1"
            android:layout_weight="1"
            />
    </LinearLayout>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/iv"
        android:layout_below="@+id/li"
        android:src="@mipmap/zyfzyf"
        />


</RelativeLayout>

package com.example.jreduch01;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private Button login;
    private Button rgdt;
    private Button exit;
    private EditText user;
    private EditText pwd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        login = (Button) findViewById(R.id.bt1);
        rgdt = (Button) findViewById(R.id.bt2);
        exit= (Button) findViewById(R.id.bt4);
        user= (EditText) findViewById(R.id.et);
        pwd = (EditText) findViewById(R.id.et_pwd);
        /*
        本类监听需要实现view.onClickListener接口
        再设置.setOnClickListener(this);
         */
        exit.setOnClickListener( new Bt4_clicklisn());
        rgdt.setOnClickListener(this);

        //匿名监听
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if (user.getText().toString().equals("123")){
                   //跳转画面
                   Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                   startActivity(intent);
               }else  if (view.getId() == R.id.bt1)
               {
                   Toast.makeText(getBaseContext(), "你点击登陆按钮", Toast.LENGTH_SHORT).show();
               }
            }
        });
    }

    //本类监听
    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.bt1)
        {
            Toast.makeText(getBaseContext(), "你点击登陆按钮", Toast.LENGTH_SHORT).show();
        }else if (view.getId() == R.id.bt2){
            Toast.makeText(getBaseContext(), "你点击注册按钮", Toast.LENGTH_SHORT).show();
        }

        //布局监听
    }

    public void reSet(View v)
    {
        user.setText("");
        pwd.setText("");
    }

    //内部类监听
public  class Bt4_clicklisn implements View.OnClickListener{
        @Override
        public  void onClick(View v){
            finish();
        }
    }
}


<span style="font-size:24px;"><strong>2.GridLayout<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">网格布局</span></strong></span>

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="3"
    tools:context="com.example.jreduch01.GridActivity">

    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zyfzyfzyf"

        />
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zz"

        />
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zyfzyfzyf"

        />
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zz"/>
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zyfzyf"/>
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zyfzyfzyf"

        />
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zz"/>
    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zyfzyf"/>

    <ImageView
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:src="@mipmap/zyfzyf"

        android:layout_row="7"
        android:layout_column="0" />


</GridLayout>


3.RelativeLayout相对布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="com.example.jreduch01.RelativeActivity">
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="腾讯QQ"
    android:textSize="25sp"
    android:id="@+id/tx1"
    android:textColor="#fb0d0d0d"
    android:gravity="center"
    />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tx1"
        android:orientation="horizontal"
        android:id="@+id/li"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@mipmap/qqq"
            android:text="QQ登陆"
            android:textSize="35sp"
            android:id="@+id/tx2"
            android:textColor="#fb0d0d0d"
            android:layout_weight="1"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="亿万用户已选择QQ账号登陆应用"
            android:textSize="10sp"
            android:id="@+id/tx3"
            android:textColor="#fb0d0d0d"
            android:layout_weight="1"
            />
    </LinearLayout>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/et"
        android:hint="QQ账号/邮箱/手机号"
        android:layout_below="@+id/li"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/et_pwd"
        android:hint="QQ密码"
        android:layout_below="@+id/et"
        android:inputType="textPassword"
        android:imeOptions="actionGo"

        />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登陆"
        android:id="@+id/button"
        android:textSize="25sp"
        android:textColor="#fdfdfd"
        android:background="@drawable/login_bg"
        android:layout_below="@+id/et_pwd"
        />
</RelativeLayout>


4.TableLayout 表格布局

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TableRow>
    <Button android:text="1"/>
    <Button android:text="1"/>
    <Button android:text="1"/>
    <Button android:text="1"/>
</TableRow>

    <TableRow>
        <TableLayout android:layout_span="3">
            <TableRow>
                <Button android:text="1"/>
                <Button android:text="1"/>
                <Button android:text="1"/>
            </TableRow>
            <TableRow>
                <Button android:text="1"
                    android:layout_span="2"/>
                <Button android:text="1"/>
            </TableRow>
        </TableLayout>
        <Button android:text="1"
            android:layout_height="match_parent"/>
    </TableRow>
    <TableRow>
        <Button android:text="1"/>
        <Button android:text="1"
            android:layout_span="3"/>

    </TableRow>
</TableLayout>


  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值