现在又是12点了。今日比较有意义的事情就是使用到了framelayout。还是之前一样,不唠叨!记录每一点收获。
一、动机: 我想在ImageView 上面放置textview 控件,来显示文字,这样我就不需要去画背景了。像是在偷懒。
二、办法:从度娘那里获得一个android 控件 《Framelayout》。
使用Framelayout 的原因是:可以将控件层叠起来。
三、使用方法
1、在已有的xml 布局文件《activity_main.xml》中,放置Framelayout。方法很简单,找到控件托放进去就OK了。
2、将Textview 控件的xml 文件放到Framelayout 的xml 文件中。这样Textview 就成了Framelayout 里面的控件了。
像下面:
<FrameLayout
android:id="@+id/frameLayout2"
android:layout_width="394dp"
android:layout_height="279dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView /*好吧,我是拷贝进来的 */
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="289dp"
android:visibility="visible"
app:srcCompat="@drawable/line"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="86dp" />
<TextView /*好吧,我是拷贝进来的 */
android:id="@+id/second_tv"
android:layout_width="368dp"
android:layout_height="112dp"
android:layout_marginStart="10dp"
android:layout_marginTop="40dp"
android:fontFamily="serif"
android:text="second"
tools:layout_editor_absoluteX="21dp"
tools:layout_editor_absoluteY="0dp" />
<TextView
android:id="@+id/week_tv"
android:layout_width="237dp"
android:layout_height="79dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="150dp"
android:text="week"
app:layout_constraintBottom_toTopOf="@+id/guideline5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</FrameLayout>
这个FrameLayout 控件是我在UI 界面拖进去的,然后在activity_main.xml 文件中就生成了<FrameLayout> </FrameLayout>结构。然后将本在主布局文件里面的TextView 控件,拷贝到这里面来。
3、将TextView 拷贝到FrameLayout中后,更改TextView 的位置只能使用相对于FrameLayout 的距离进行位置调整。一点一点的调位置到自己喜欢为止。
4、我是用的比较傻的办法,距离是每一个边挨着调节的。还有更好的办法,希望看到这篇文章的战友指点迷津。
甚是感谢。