リア充爆発日記

You don't even know what ria-ju really is.

Viewのレイアウト調整でよく使う事項メモ

随時追加系メモ

位置調整系

テキストを真ん中に寄せる
  • layout_gravity="center"
    • その他center系を適宜使う
等間隔にViewを置く。
  • layout_weightを使う
    • widthかheightの指定(水平方向の場合はlayout_width)は意味がなくなるので0dpにしたほうがパフォーマンスがよくなる。
            <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textSize="10sp"
                    android:text="@string/debug"
                    />
            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textSize="10sp"
                android:text="@string/debug"
                />

ってやると、ボタンとかくっついちゃって困る時があるのでそういうときはダミーのViewを挟んで調整する。

            <Button
                    android:layout_width="0dp"
                    android:layout_height="48dp"
                    android:layout_weight="10"
                    android:textSize="10sp"
                    android:text="@string/signup_register"
                    android:background="@color/splash_button"
                    />

            <View
                    android:layout_width="0dp"
                    android:layout_height="1dp"
                    android:layout_weight="2"
                    />

            <Button
                android:layout_width="0dp"
                android:layout_height="48dp"
                android:layout_weight="10"
                android:textSize="10sp"
                android:text="@string/signup_signin"
                android:background="@color/splash_button"
                />
View左
テキストに画像をトッピングする

色調整系

背景を透明にする
  • colorで指定するRGBの"前"に00~FFで透明度を指定する。
    • "#D0CCCCCC"の場合D0が透明度

かたち調整系

角丸にする。
  • drawableのxmlでやる
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

    <corners
        android:radius="10dp"
    />

    <solid
        android:color="@color/button"
        />

</shape>

ここのcornersのradiusの数字を変えて丸みを変える。

その他

ボーダーを付ける
EditViewの中にアイコンを置く
  • 検索窓に虫メガネ置きたいときなど
  • drawableRightなどのdrawableシリーズを使う。
ボタンに影をつける(ドロップシャドウ)はできないらしい

って誰かが言ってた。