2019-03-15

实验内容:关于线性布局、约束布局及表格布局的使用

主要代码:

主界面:
      btn_ll = findViewById(R.id.btn_ll);
      btn_cl = findViewById(R.id.btn_cl);
      btn_tl = findViewById(R.id.btn_tl);
   private void setListeners() {
        OnClick onClick = new OnClick();
        btn_ll.setOnClickListener(onClick);
        btn_cl.setOnClickListener(onClick);
        btn_tl.setOnClickListener(onClick);
    }
    private class OnClick implements View.OnClickListener {
        Intent intent;
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_ll :
                    intent = new Intent(MainActivity.this,LinearLayoutActivity.class);
                    break;
                case R.id.btn_cl :
                    intent = new Intent(MainActivity.this,ConstraintLayoutActivity.class);
                    break;
                case R.id.btn_tl :
                    intent = new Intent(MainActivity.this,TableLayoutActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
线性布局:
<LinearLayout 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:orientation="vertical"
    android:background="@color/colorBlack"
    tools:context=".LinearLayoutActivity"
    android:padding="5dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="One,One"
            android:textSize="18sp"
            android:textColor="@color/colorGrey"
            android:textAllCaps="false"
            android:background="@drawable/shape_button"
            android:layout_marginRight="5dp"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="One,Two"
            android:textSize="18sp"
            android:textColor="@color/colorGrey"
            android:textAllCaps="false"
            android:background="@drawable/shape_button"
            android:layout_marginRight="5dp"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="One,Three"
            android:textSize="18sp"
            android:textColor="@color/colorGrey"
            android:textAllCaps="false"
            android:background="@drawable/shape_button"
            android:layout_marginRight="5dp"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="One,Four"
            android:textSize="18sp"
            android:textColor="@color/colorGrey"
            android:textAllCaps="false"
            android:background="@drawable/shape_button" />
    </LinearLayout>
    ...
    ...
</LinearLayout>
约束布局:
 <android.support.constraint.ConstraintLayout 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:background="@color/colorBlack"
    android:minHeight="0dp"
    tools:context=".ConstraintLayoutActivity">

    <Button
        android:id="@+id/bt_red"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="344dp"
        android:background="@color/colorRed"
        android:text="Red"
        android:textSize="25sp"
        app:layout_constraintBottom_toBottomOf="@+id/bt_orange"
        app:layout_constraintEnd_toStartOf="@+id/bt_orange"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/bt_orange"
        app:layout_constraintVertical_bias="0.0" />
        ...
        ...
</android.support.constraint.ConstraintLayout>
表格布局:
  ...
  <TableRow>
        <TextView
            android:paddingLeft="20dp"
            android:text="@string/open"
            android:textSize="25sp"
            android:textColor="@color/colorGrey"
            android:layout_column="0"/>
        <TextView
            android:text="Ctrl-O"
            android:textSize="25sp"
            android:textColor="@color/colorGrey"
            android:layout_column="2"
            android:gravity="right"/>
    </TableRow>
    ...
    ...
    <TableRow>
        <View android:layout_height="3dp"
            android:background="@color/colorGrey"/>
        <View android:layout_height="3dp"
            android:background="@color/colorGrey"
            android:layout_column="2"/>
    </TableRow>
    ...

截图:

①总界面:
image
②线性布局:
image
③约束布局:
image
④表格布局:
image
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 每日检视122/365 起床:5:30 就寝:11:10 天气:晴 心情:平静 纪念日: 叫我起床的不是闹钟是梦想...
    洒脱转身阅读 163评论 0 0
  • 一、引言 从老大搭好的框架中看到了MVP的设计模式,一头雾水不知如何使用,特意去网上学习,做了Demo,特来做下纪...
    wodenide阅读 571评论 0 0
  • 今天3. 15,回头一看,2019年股市的这头牛宝宝已经快3个月大了。本小白是去年进的市场,到现在大半年了,小有获...
    白驹行空阅读 189评论 0 0
  • 文|米苔 一 谢亦暄早早的来到教室,因为她后悔了,昨天就不应该把信放在梁乔的抽屉里的。 她想了整整一个晚上,于是今...
    米苔阅读 475评论 0 3
  • 犹豫了很长时间,还是想写一篇关于成都的游记,算是给自己留一个简单的回忆吧。 年还没有过完,我...
    我的名字叫十一阅读 511评论 4 7

友情链接更多精彩内容