我正在参加「兔了个兔」创意投稿大赛,详情请看:「兔了个兔」创意投稿大赛
前言
没想到写这篇是掐着活动最后时间写的,所以我就以一副对联收尾,也算是为本次活动喝彩了,下面我们来看看如何实现这副对联的展示的。
正篇
实现方法
首先,我们先添加一个线性布局,设置竖直方向属性以及背景颜色设置为红色,然后为其内部添加子布局,第一个是TextView,作为横幅,首先宽高内容大小自适应,然后布局居中。
接着我们去设计左右竖着的上下联,我们采用FrameLayout帧布局,然后内部写子布局TextView分别start和end,且宽度设置为40dp,正好一字一行形成竖着写的样式,当然为了让对联更紧凑,我们设置了layout_marginEnd和layout_marginStart属性,让上下联靠拢。最后我们在中间加一张福的图片就大功告成!
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".RabbitSecond">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/red"
android:text="@string/rabbit_h"
android:textSize="25sp"
android:textStyle="bold"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="@string/rabbit_1"
android:background="@color/red"
android:textSize="25sp"
android:textStyle="bold"
android:layout_marginStart="20dp"
android:gravity="center"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/rabbit_fu"
android:layout_gravity="center|top"/>
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="20dp"
android:text="风调雨顺颂华年"
android:background="@color/red"
android:textSize="25sp"
android:textStyle="bold"
android:gravity="center"/>
</FrameLayout>
</LinearLayout>
最终效果
最终我们看到形成贴在门上的对联样式,中间还有一个福:
总结
很简单的布局效果,也是最容易实现的效果了,比起在web上写对联,我感觉容易了许多,这就是熟练与否的效果,所以后续我还会继续练习web开发。