背景
在这里继续学习Android Studio的使用方法,编写一个截图演示工具 1,学习图像视图ImageView进行截图的操作。
页面布局
现在想要设计一个单页面截图展示工具,主要有4个控件(1个TextView,1个ImageView,2个Button),从上到下、从左到右的布局分别是
- 聊天窗口,宽度是半个屏幕(50%),高度90%,用来展示聊天文本;
- 截图窗口,宽度半个屏幕(50%),高度90%,用来展示从左边聊天窗口截取的图片;
- 聊天按钮,宽度50%,高度10%,点击后在聊天窗口显示事先设计好的随机的聊天文本;
- 截图按钮,宽度50%,高度10%,点击后从左边聊天窗口截取图片,然后在截图窗口显示。
布局文件的编写
activity_main.xml
的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline_1"
app:layout_constraintGuide_percent=".90"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline_2"
app:layout_constraintGuide_percent=".50"
android:orientation="vertical"/>
<TextView
android:id="@+id/tv_capture"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#0073C2FF"
android:textColor="#000000"
android:textSize