12
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android レイアウトで使う tools:の便利まとめ

Posted at

本家
https://developer.android.com/studio/write/tool-attributes

##デザインする時に確認用として使う

android:ができることがtools:でもできる

###tools:text
TextViewで固定字を入れるのをやめてtoolsで確認文字を入れる
toolsで設定した太郎textがxmlのクリックした時に確認できる

<TextView
        android:id="@+id/my_rank"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="太郎"
        />

###tools:visibility="invisible"
表示テストに使えばいい

###tools:context=".MainActivity"
自分の所属しているactivityなど指定し、onClickなど作る時に便利

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity" >

###tools:itemCount
RecyclerViewのサイズをカスタマイズして確認

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:itemCount="3"/>

###tools:listitem / tools:listheader / tools:listfooter
Listviewの事前確認
現在はほとんどRecyclerViewを使うから必要ないかもしれないが、簡単なレイアウトには使えそう

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:listitem="@layout/sample_list_item"
    tools:listheader="@layout/sample_list_header"
    tools:listfooter="@layout/sample_list_footer" />

###"@tools:sample/*" resources

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:text="@tools:sample/lorem" />

"@tools:sample/*" resources
ダミーのリソースで確認できる、これは便利

   //これだと長い文章をわざわざタイプしなくでも@tools:sample/lorem/randomで確認できる
   <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:text="@tools:sample/lorem/random" />

    //ダミーの画像で確認できる
    <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:src="@tools:sample/backgrounds/scenic" />

使えるリソース一覧

Attribute value	Description of placeholder data
@tools:sample/full_names	Full names that are randomly generated from the combination of @tools:sample/first_names and @tools:sample/last_names.
@tools:sample/first_names	Common first names.
@tools:sample/last_names	Common last names.
@tools:sample/cities	Names of cities from across the world.
@tools:sample/us_zipcodes	Randomly generated US zipcodes.
@tools:sample/us_phones	Randomly generated phone numbers with the following format: (800) 555-xxxx.
@tools:sample/lorem	Placeholder text that is derived from Latin.
@tools:sample/date/day_of_week	Randomized dates and times for the specified format.
@tools:sample/date/ddmmyy
@tools:sample/date/mmddyy
@tools:sample/date/hhmm
@tools:sample/date/hhmmss
@tools:sample/avatars	Vector drawables that you can use as profile avatars.
@tools:sample/backgrounds/scenic	Images that you can use as backgrounds.

などなど

12
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?