day01

  1. Android studio 下的布局在content_main.xml中
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    app:layout_behavior="@string/appbar_scrolling_view_behavior"    tools:context="com.example.liuxiaoer.myapplication.MainActivity"    tools:showIn="@layout/activity_main"    android:orientation="vertical"    >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello 33!" />    <EditText        android:id="@+id/inputText"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="30dp"        android:background="#ff0000"        android:text="请输入"        />    <Button        android:id="@+id/btn"        android:layout_width="300dp"        android:layout_height="30dp"        android:text="百度一下,你就知道"        android:layout_marginTop="30dp"        /></LinearLayout>

1.布局方式有LinearLayout :线性布局方式 对应android:orientation="vertical" 水平和垂直两种
系统默认是relativelayout 当然也有 绝对布局 absolutelayout

  1. 安卓设置控件属性 类似RN或H5中的在第一个标签内部进行键值对的布局
    wrap_content:包裹内容 match_parent:和父标签一样大 以前是line_parent好像是这个可能打错了现在已经过期了
    3.设置宽高有6中数据的类型px pt in mm dp sp
    一半宽高用dp 文本用sp
    4.MainActivity中的入口方法是onCreate
    setContentView(R.layout.activity_main);这个是设置它对应的view是R下layout中的activity_main R中都是内部final int等
    可以通过给控件设置id来找到对应的控件类似iOS的tag:android:id="@+id/btn"
    5.按钮的点击
 // 通过id找到按钮    Button bt = (Button) findViewById(R.id.btn);    bt.setOnClickListener(new BtnListen());    // ATTENTION: This was auto-generated to implement the App Indexing API.    // See https://g.co/AppIndexing/AndroidStudio for more information.}class BtnListen implements View.OnClickListener {    @Override    public void onClick(View v) {        // 得到输入框的文字        EditText eT = (EditText) findViewById(R.id.inputText);        System.out.println(eT.getText().toString());    }}
```setOnClickListener设置按钮点击的监听者这个方法是View的方法
按钮继承View 需要传入一个OnClickListener这个是一个接口 需要实现方法
这里 实现接口方法的快捷键是control+i;
6、打电话
```objc
// 告诉系统一个意图Intent it = new Intent();// 设置打电话的电话号码it.setData(Uri.parse("tel:"+et.getText().toString()));// 告诉系统我们的意图是打电话it.setAction(Intent.ACTION_CALL);// 开启打电话 startActivity(it);

7.系统应用 必须获取用户权限
在AndroidMainfestxml中配置
<uses-permission android:name="android.permission.CALL_PHONE"/>
:打电话

  1. 按钮有4种点击方法
    -01. 直接在xml中绑定点击的方法:
    android:onClick="clickBtn2",这个时候 需要在对应的activity中添加public void
    clickBtn2(View v)(){}
    -02.绑定id android:id="@+id/btn_02"
    在activity中获取id btn2 = (Button)findViewById(R.id.btn_02)
    设置按钮的监听者 se'tOnclicklisen()
    需要传入接口 可以传入this那么本类就需要实现对应的onclick 可以使用control+i的快捷键 实现onclick方法
    -03.可以传入一个匿名内部类
    -04.可以创建一个类实现对应的方法的点击 传入这个类的对象即可

9.发送短信 SmsManager

public void sendMns(View v){    // 更具ID获取对应的信息 和 来源 btn    EditText et1 = (EditText)findViewById(R.id.account);    EditText et2 = (EditText)findViewById(R.id.password);    SmsManager sms = SmsManager.getDefault();    for(String s : sms.divideMessage(et1.getText().toString())){        sms.sendTextMessage(et1.getText().toString(),null,et2.getText().toString(),null,null);    }}

10linerarlayout 线性布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    app:layout_behavior="@string/appbar_scrolling_view_behavior"    tools:context="com.example.liuxiaoer.sendemal.MainActivity"    tools:showIn="@layout/activity_main"    android:orientation="vertical"    android:weightSum="2"    >    <LinearLayout        android:weightSum="3"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:background="@android:color/darker_gray"        android:orientation="horizontal"        >       <TextView           android:layout_width="0dp"           android:layout_weight="1"           android:layout_height="match_parent"           android:background="#ff0000"           />        <TextView            android:layout_width="0dp"            android:layout_weight="1"            android:layout_height="match_parent"            android:background="#00ff00"            />        <TextView            android:layout_width="0dp"            android:layout_weight="1"            android:layout_height="match_parent"            android:background="#0000ff"            />    </LinearLayout>    <LinearLayout        android:weightSum="3"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:background="@android:color/darker_gray"        android:orientation="vertical"        >        <TextView            android:layout_width="match_parent"            android:layout_weight="1"            android:layout_height="0dp"            android:background="#ff0000"            />        <TextView            android:layout_width="match_parent"            android:layout_weight="1"            android:layout_height="0dp"            android:background="#00ff00"            />        <TextView            android:layout_width="match_parent"            android:layout_weight="1"            android:layout_height="0dp"            android:background="#0000ff"            />    </LinearLayout></LinearLayout>

常用布局方法之一;
父节点用weights sum 设置分几分
子节点用l子控件ayout weight分剩下的等分
gravity是自己内部的分布 付控件的oriengation垂直或者水平会导致子控件对应的水平或者垂直的属性失效 。 layout_gravity 是相对应付控件的位置 。都要考虑父亲的oriengation是哪个。
visibility:3中 可见 不可见占位置 gone不可见不占位置 和H5中的那个类似

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容