Android手机尺子项目
该项目就是让自己的手机屏幕变成一把尺子,看起来比较酷炫,而且可以很容易的进行测量。接下来看一下效果如何。
这个小项目其实没有什么特别的难度,关键是对于xml文件当中的textView进行重写。现在让我们来看一下代码:
首先是布局文件activity_main.xml的代码。
//这下面采用的是线性布局,在线性布局下面几个文本textview
<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="horizontal"
>
<com.ruler.MC //表示的是该textview继承自重写自com.ruler.MC
android:layout_width="10mm"
android:layout_height="10mm"
android:text="1cm"
android:textSize="10pt"
android:background="#ff00ff"
android:layout_gravity="c