一、线性布局LinearLayout

线性布局LinearLayout
相对布局RelativeLayout
image.png
layout_width : match_parent匹配父控件 wrap_content根据文字内容匹配

image.png

二、TextView

常用属性设置

  1. <TextView
  2. android:id="@+id/textViewOne"
  3. android:layout_width="100dp"
  4. android:layout_height="wrap_content"
  5. android:text="Hello Albert"
  6. android:maxLines="1" 最大行数
  7. android:ellipsize="end" 最后显示为...
  8. android:textSize="20sp" 字体大小
  9. android:drawableRight="@drawable/awg_pic_tx_run_playing" 在文字右侧插入图片
  10. android:layout_marginLeft="@dimen/dp_20"
  11. android:textColor="@color/red"/>
  1. package com.rigol.station.generator.awg;
  2. import android.app.AlertDialog;
  3. import android.content.DialogInterface;
  4. import android.content.Intent;
  5. import android.graphics.Paint;
  6. import android.os.Bundle;
  7. import android.view.WindowManager;
  8. import androidx.annotation.Nullable;
  9. import com.rigol.station.generator.SplashActivity;
  10. import com.rigol.station.generator.common.base.BaseActivity;
  11. import com.rigol.station.generator.databinding.ActivityAlbertTestBinding;
  12. public class AwgTestActivity extends BaseActivity
  13. {
  14. private ActivityAlbertTestBinding mBinding;
  15. @Override protected void onCreate(@Nullable Bundle savedInstanceState)
  16. {
  17. super.onCreate(savedInstanceState);
  18. //这句代码是固定的
  19. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  20. //创建Binding实例
  21. mBinding = ActivityAlbertTestBinding.inflate(getLayoutInflater());
  22. //设置上下文内容(Binding的View)
  23. setContentView(mBinding.getRoot());
  24. //设置TextView文本有下划线
  25. mBinding.textViewOne.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
  26. //去除锯齿
  27. mBinding.textViewOne.getPaint().setAntiAlias(true);
  28. //Button的点击事件
  29. mBinding.TestButton.setOnClickListener(v->{
  30. //弹框
  31. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  32. builder.setTitle("AWG");
  33. builder.setMessage("AWG交互体验测试");
  34. builder.setPositiveButton("Good", new DialogInterface.OnClickListener()
  35. {
  36. @Override public void onClick(DialogInterface dialog, int which)
  37. {
  38. }
  39. });
  40. AlertDialog dialog = builder.create();
  41. dialog.show();
  42. //界面跳转
  43. Intent intent = new Intent(this, SplashActivity.class);
  44. startActivity(intent);
  45. });
  46. }
  47. }

跑马灯效果

  1. <TextView
  2. android:id="@+id/textViewTwo"
  3. android:layout_width="@dimen/dp_80"
  4. android:layout_height="wrap_content"
  5. android:text="Hello Albert Hello Albert Hello Albert Hello Albert Hello Albert"
  6. android:singleLine="true"
  7. android:ellipsize="marquee"
  8. android:marqueeRepeatLimit="marquee_forever"
  9. android:focusable="true"
  10. android:focusableInTouchMode="true"
  11. android:textSize="20sp"
  12. android:layout_marginLeft="@dimen/dp_20"
  13. android:textColor="@color/red"/>

三、Button

常用属性

layout_below = “@id/btn_1 在btn_1的下方
image.png

自定义Button样式

在res-drawable下面添加Drawable Resource File
image.png
增加代码:

  1. 最外面的形状为方形,solid实心颜色为yellow,corners圆角为100dp
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  4. <solid android:color="@color/yellow"/>
  5. <corners android:radius="@dimen/dp_100"/>
  6. </shape>

image.png

虚线框stroke
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="1dp"
        android:color="#FF9900"/>
    <corners android:radius="@dimen/dp_20"/>
</shape>

image.png

四、EditText、RadioButton、CheckBox

都可以用drawable来自定义控件类型

五、ImageView

src:图片源
scaleType:拉伸方式
image.png
网络图片显示到本地:
https://github.com/bumptech/glide
在build.gradle中链接上库
详细用法参考github上面的使用说明

在AndriodManifest.xml中: