以前まではimageViewの上にテキストを載せる手法を載せたのですが、今回はテキストの
backgroundの色を変えてレイアウトが重なったようにみせかけるレイアウト方法を
載せていきます。
方法は簡単で、textviewを通常通りに定義して各方向のpaddingを使うことで
重なったようなレイアウトにすることができます。
この手法はrelativeLayoutでも使うことができるので、アプリの見出しとかにもがんがん
使えそうです。
<pre><RelativeLayout android:id="@+id/relativeLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="MissingConstraints"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff" android:paddingBottom="10dp" android:paddingStart="20dp" android:paddingEnd="20dp" android:paddingTop="10dp" android:text="是非もないよね!" android:gravity="center" android:textSize="16sp" android:textStyle="bold" /></pre> <pre></RelativeLayout></pre>
ポイントは各四方のpaddingで、bottomとtopの値を調整することで均等に
テキストを見せることができるので使い慣れておきましょう。
imageviewと組み合わせるよりも、書く時のコードもメンテナンス時の直すコードも
少ないので、特殊なカスタムボタンを作る時以外はこっちのが断然おすすめです。