استعمال از :tools به مکان :android
جایگزینی پیشوند :android به مکان پیشوند :tools روی هر ویژگی به ما قابلیت و امکان میدهد که دادههای مثال را در پیشاکران لیآوت خویش وارد کنیم و همچنینی ویژگی را فقط در پیشاکران لیآوت غیرفعال نماییم. در شرایطیکه به ویژگیهای tools:text و tools:visibility که در اولِ نوشتهعلمی اشاره کردیم اعتنا کرده باشید، متوجه می شوید کهاین ویژگیها بهاین تیم وابستگی دارا هستند و مقدار ویژگی تا مجال اعمال مقداردهی نمی شود، ولی در صورتیکه برای اکران جلوه قبل از اعمال و در مرحله پیشاکران لیآوت مصرف شود بسیار طراحی اپلیکیشن در مشهد اثر گذار خواهد بود.
این ویژگیها را روی لیآوت contact_item.xml که طرحبندی مورد منفرد مخاطبین را در نرم افزار Contacts+ ما تعریف و تمجید مینماید آزمون می کنیم. درپی میتوانید پیشاکران و کد پیشاکران کنونی این طرحبندی را ملاحظه کنید:
1
2 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:app="http://schemas.android.com/apk/res-auto"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:id="@+id/contact_card_view"
7 android:layout_gravity="center"
8 android:layout_width="match_parent"
9 android:layout_height="wrap_content"
10 app:cardCornerRadius="9dp"
11 android:clickable="true"
12 android:focusable="true"
13 app:cardElevation="3dp"
14 android:padding="16dp"
15 app:cardUseCompatPadding="true"
16 android:foreground="?attr/selectableItemBackground">
17
18 19 android:layout_width="match_parent"
20 android:layout_height="wrap_content"
21 android:layout_margin="8dp">
22
23 24 android:id="@+id/avatar_image"
25 android:layout_width="38dp"
26 android:layout_height="38dp"
27 android:contentDescription="User avatar"
28 android:scaleType="centerCrop"
29 tools:src="@drawable/ic_face_male"
30 app:layout_constraintTop_toTopOf="parent"
31 android:layout_marginLeft="8dp"
32 android:layout_marginStart="8dp"
33 app:layout_constraintLeft_toLeftOf="parent"
34 tools:ignore="HardcodedText"/>
35
36 37 android:id="@+id/contact_name_textview"
38 android:layout_width="wrap_content"
39 android:layout_height="wrap_content"
40 android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
41 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
42 android:layout_marginLeft="8dp"
43 android:layout_marginStart="8dp"
44 tools:text="John Doe"
45 app:layout_constraintTop_toTopOf="parent"/>
46
47 48 android:id="@+id/contact_mobile_number_static_textview"
49 android:layout_width="wrap_content"
50 android:layout_height="wrap_content"
51 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
52 android:textColor="@color/colorSecondaryText"
53 android:text="@string/mobile_number_static_text"
54 android:layout_marginTop="8dp"
55 app:layout_constraintTop_toBottomOf="@+id/contact_name_textview"
56 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
57 android:layout_marginLeft="8dp"
58 android:layout_marginStart="8dp"/>
59
60 61 android:id="@+id/contact_mobile_number_textview"
62 android:layout_width="wrap_content"
63 android:layout_height="16dp"
64 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
65 android:textColor="@color/colorSecondaryText"
66 tools:text="(800) 555-7150"
67 android:layout_marginTop="8dp"
68 app:layout_constraintTop_toBottomOf="@+id/contact_name_textview"
69 app:layout_constraintLeft_toRightOf="@+id/contact_mobile_number_static_textview"
70 android:layout_marginLeft="@dimen/contact_item_static_textview_margin"
71 android:layout_marginStart="@dimen/contact_item_static_textview_margin"/>
72
73 74 android:id="@+id/contact_home_number_static_textview"
75 android:layout_width="wrap_content"
76 android:layout_height="wrap_content"
77 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
78 android:textColor="@color/colorSecondaryText"
79 android:text="@string/home_number_static_text"
80 android:layout_marginTop="8dp"
81 app:layout_constraintTop_toBottomOf="@+id/contact_mobile_number_static_textview"
82 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
83 android:layout_marginLeft="8dp"
84 android:layout_marginStart="8dp"/>
85
86 87 android:id="@+id/contact_home_number_textview"
88 android:layout_width="wrap_content"
89 android:layout_height="wrap_content"
90 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
91 android:textColor="@color/colorSecondaryText"
92 tools:text="(800) 555-7150"
93 android:layout_marginTop="8dp"
94 app:layout_constraintTop_toBottomOf="@+id/contact_mobile_number_textview"
95 app:layout_constraintLeft_toRightOf="@+id/contact_home_number_static_textview"
96 android:layout_marginLeft="8dp"
97 android:layout_marginStart="8dp"/>
98
99 100 android:id="@+id/contact_office_number_static_textview"
101 android:layout_width="wrap_content"
102 android:layout_height="wrap_content"
103 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
104 android:textColor="@color/colorSecondaryText"
105 android:text="@string/office_number_static_text"
106 android:layout_marginTop="8dp"
107 app:layout_constraintTop_toBottomOf="@+id/contact_home_number_textview"
108 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
109 android:layout_marginLeft="8dp"
110 android:layout_marginStart="8dp"/>
111
112 113 android:id="@+id/contact_office_number_textview"
114 android:layout_width="wrap_content"
115 android:layout_height="wrap_content"
116 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
117 android:textColor="@color/colorSecondaryText"
118 tools:text="(800) 555-7150"
119 android:layout_marginTop="8dp"
120 app:layout_constraintTop_toBottomOf="@+id/contact_home_number_textview"
121 app:layout_constraintLeft_toRightOf="@+id/contact_office_number_static_textview"
122 android:layout_marginLeft="8dp"
123 android:layout_marginStart="8dp"/>
124
125 126 android:id="@+id/contact_email_static_textview"
127 android:layout_width="wrap_content"
128 android:layout_height="wrap_content"
129 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
130 android:textColor="@color/colorSecondaryText"
131 android:text="@string/email_static_text"
132 android:layout_marginTop="8dp"
133 app:layout_constraintTop_toBottomOf="@+id/contact_office_number_static_textview"
134 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
135 android:layout_marginLeft="8dp"
136 android:layout_marginStart="8dp"/>
137
138 139 android:id="@+id/contact_email_textview"
140 android:layout_width="wrap_content"
141 android:layout_height="wrap_content"
142 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
143 android:textColor="@color/colorSecondaryText"
144 tools:text="john.doe@mail.com"
145 android:layout_marginTop="8dp"
146 app:layout_constraintTop_toBottomOf="@+id/contact_office_number_textview"
147 app:layout_constraintLeft_toRightOf="@+id/contact_email_static_textview"
148 android:layout_marginLeft="8dp"
149 android:layout_marginStart="8dp"/>
150
151 152 android:id="@+id/contact_address_static_textview"
153 android:layout_width="wrap_content"
154 android:layout_height="wrap_content"
155 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
156 android:textColor="@color/colorSecondaryText"
157 android:text="@string/address_static_text"
158 android:layout_marginTop="8dp"
159 app:layout_constraintTop_toBottomOf="@+id/contact_email_static_textview"
160 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
161 android:layout_marginLeft="8dp"
162 android:layout_marginStart="8dp"/>
163
164 165 android:id="@+id/contact_address_textview"
166 android:layout_width="wrap_content"
167 android:layout_height="wrap_content"
168 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
169 android:textColor="@color/colorSecondaryText"
170 tools:text="San-Fransisco, US"
171 android:layout_marginTop="8dp"
172 app:layout_constraintTop_toBottomOf="@+id/contact_email_textview"
173 app:layout_constraintLeft_toRightOf="@+id/contact_address_static_textview"
174 android:layout_marginLeft="8dp"
175 android:layout_marginStart="8dp"/>
176
177 178 android:id="@+id/favourite_button"
179 android:layout_width="38dp"
180 android:layout_height="38dp"
181 android:src="@drawable/ic_star_empty_green"
182 android:background="?selectableItemBackground"
183 android:layout_marginRight="4dp"
184 android:layout_marginEnd="4dp"
185 app:layout_constraintRight_toLeftOf="@+id/divider_line"
186 app:layout_constraintTop_toTopOf="parent"
187 android:layout_marginLeft="8dp"
188 android:layout_marginStart="8dp"/>
189
190 191 android:id="@+id/divider_line"
192 android:layout_height="38dp"
193 android:layout_width="1dp"
194 android:background="@color/colorSecondaryText"
195 android:layout_marginStart="4dp"
196 android:layout_marginLeft="4dp"
197 app:layout_constraintTop_toTopOf="parent"
198 app:layout_constraintRight_toLeftOf="@+id/call_button"
199 android:layout_marginRight="@dimen/contact_item_divider_margin"
200 android:layout_marginEnd="@dimen/contact_item_divider_margin"/>
201
202 203 android:id="@+id/call_button"
204 android:layout_width="38dp"
205 android:layout_height="38dp"
206 android:src="@drawable/ic_phone"
207 android:background="?selectableItemBackground"
208 android:layout_marginRight="8dp"
209 android:layout_marginEnd="8dp"
210 app:layout_constraintRight_toRightOf="parent"
211 app:layout_constraintTop_toTopOf="parent"
212 android:layout_marginStart="4dp"
213 android:layout_marginLeft="4dp"/>
214
215
216
217
مشاهده بی نقص کدها
به ویژگیهای tools:text در موادتشکیل دهنده و ویژگی tools:src در عنصر اعتنا نمائید. ما بهاین جهت از این ویژگی به کار گیری می کنیم که هم دادهها در طول مجال انجام از دیتابیس یا این که API بازیابی می شوند و هم در موادسازنده View مرتبط اکران پیدا مینمایند. فارغ از به کارگیری از ویژگیهای tools مورد کارت ما چیزی مانند تحت خواهد بود:
این حالت پاره ای سردرگم کننده میباشد. استعمال از ویژگیهای با پیشوند :tools قابلیت بصریسازی دادهها را در پیشاکران لیآوت در مشت ما قرار میدهند و خواهیم توانست این طرحبندی را با تمرکز بیشتری آزمایش کنیم.
همینطور خواهیم توانست از ویژگیهای با پیشوند :tools برای حذف یک ویژگی با پیشوند :android فقط از پیشاکران لیآوت استعمال کنیم. برای مثال فرض نمائید که میخواهیم موردهای مخاطبان ما فقط اسم و شماره یاور کاربر را اکران دهند و داده ها دیگر را در طی کلیک کردن مخاطب به اکران بگذارند. برای فعال سازی این قابلیت و امکان کافی میباشد طول را روی 80dp تهیه کنیم و مستمع onClick را طوری اضافه کنیم که داده ها ثانویه را گشوده نماید.
چنان که میبینید بعد از گزینش طول روی 80dp دیگر توانا به دیدن فیلدهای ثانویه در پیشاکران لیآوت نیستیم. البته حل این ایراد بسیار بی آلایش میباشد. کافی میباشد "tools:layout_height=”wrap_content را به اضافه کنیم. این حالت بدان مفهوم نیز است که قابلیت به کار گیری از هر دو ویژگی فضای اسم :android و ویژگیهای مطابقت و همخوانی :tools هم زمان روی یک عنصر view وجود داراست.
tools:context
این ویژگی گزینش مینماید کهاین لیآوت به صورت پیشفرض با کدام کار مرتبط میباشد. بنابراین قابلیت و امکانهایی مانند تعیین پوسته مطلوب برای اکران یک لیآوت، رندر کردن نوار اکشن، جایی برای اضافه کردن دستگیرههای onClick و مواقعی از این دست در ادیتور یا این که پیشاکران لیآوت فعال می شوند که مستلزم استحضار از اکتیویتی میباشند.
در نمونه نرم افزار مخاطبان، این ویژگی را به تگ ریشه فرگمان مخاطبان خویش افزودیم، البته بهاین فرگمان استحضار دهیم که در اکتیویتی اساسی اضافه گردد.
1 2 xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 tools:context=".ui.activity.MainActivity">
tools:layout
این ویژگی فقط از سوی تگهای استعمال میگردد و به ادیتور راجعبه لیآوتی که می بایست از سوی پیشاکران لیآوت، باطن فرگمان ترسیم خواهد شد اگاهی می دهد. پیرو تفاوت در میان پیشاکرانهای لیآوت پوشه activity_main.xml را پیش و بعداز اضافه کردن عبارت "tools:layout=”@layout/fragment_contacts به تگ می بینید:
1
2 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:app="http://schemas.android.com/apk/res-auto"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:layout_width="match_parent"
7 android:layout_height="match_parent"
8 tools:context=".ui.activity.MainActivity">
9
10 11 android:layout_width="match_parent"
12 android:layout_height="wrap_content"
13 android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
14
15 16 android:id="@+id/toolbar"
17 android:layout_width="match_parent"
18 android:layout_height="?attr/actionBarSize"
19 app:layout_scrollFlags="scroll|enterAlways"
20 app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
21
22 23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:text="Contacts+"
26 android:textStyle="bold"
27 android:textSize="18sp"/>
28
29
30
31
32
33 34 android:id="@+id/home_fragment_container"
35 android:layout_width="match_parent"
36 android:layout_height="match_parent"
37 app:layout_behavior="@string/appbar_scrolling_view_behavior"
38 tools:layout="@layout/fragment_contacts"/>
39
40
مشاهده بی نقص کدها
tools:showIn
این ویژگی برای اشاره به یک لیآوت استعمال میگردد که از این لیآوت تحت عنوان یک include به کارگیری مینماید و از روش تگ به آن اشاره مینماید. این موقعیت به ما قابلیت می دهد که فولدر را چنان که در طی جاسازی در لیآوت والد خویش چشم میگردد ببینیم و بازنویسی کنیم. برای مثال اضافه کردن "tools:showIn=”@layout/activity_main به تگ ریشه پوشه contact_item.xml موجب میگردد که ادیتور لیآوت مارا باطن اکتیویتی اساسی از جدید ترسیم نماید:
tools:listitem | tools:listheader | tools:listfooter
این ویژگیها برای و زیرکلاسهای آن مانند و به کار گیری می شوند و کاربردشان انتخاب لیآوتی میباشد که بایستی باطن آن آداپتر به طور یک مورد لیست، هدر یا این که فوتر ترسیم خواهد شد. از جمله لیآوت fragment_contacts_xml در نرم افزار +Contacts ما یک اعلان مینماید که پیش و بعد از اضافه کردن "tools:listitem=”@layout/contact_item به طور تحت میباشد:
1
2 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:tools="http://schemas.android.com/tools"
5 xmlns:app="http://schemas.android.com/apk/res-auto"
6 android:id="@+id/contact_fragment_relative_layout"
7 android:layout_width="match_parent"
8 android:layout_height="match_parent"
9 tools:context=".ui.activity.MainActivity"
10 tools:showIn="@layout/activity_main">
11
12 13 android:id="@+id/recyclerview_contacts"
14 android:layout_width="match_parent"
15 android:layout_height="wrap_content"
16 android:gravity="center"
17 android:visibility="visible"
18 app:layoutManager="LinearLayoutManager"
19 tools:listitem="@layout/contact_item"/>
20
21
مشاهده بی نقص کدها
tools:itemCount
این ویژگی تنهاً برای به کارگیری می شود و جهت گزینش تعداد گزینههای لیست که ادیتور لیآوت بایستی در پیشاکران لیآوت رندر کردن آیتم به کارگیری قرار می گیرد.
مطابق مشاهدات ما اندروید استودیو به طور پیشفرض 10 گزینه لیست را برای اکران میدهد. از این رو به طور معمول با اضافه کردن ویژگی، تمام شیت لیآوت را پوشش می دهد و دیگر نمیقدرت موادسازنده تحت آن را روئت کرد. دراین مواقعی ویژگی tools:itemCount به ما امداد مینماید که موادتشکیل دهنده ذیل را ببینیم.
استعمال از :tools به مکان :android
جایگزینی پیشوند :android به مکان پیشوند :tools روی هر ویژگی به ما قابلیت و امکان میدهد که دادههای مثال را در پیشاکران لیآوت خویش وارد کنیم و همچنینی ویژگی را فقط در پیشاکران لیآوت غیرفعال نماییم. در شرایطیکه به ویژگیهای tools:text و tools:visibility که در اولِ نوشتهعلمی اشاره کردیم اعتنا کرده باشید، متوجه می شوید کهاین ویژگیها بهاین تیم وابستگی دارا هستند و مقدار ویژگی تا مجال اعمال مقداردهی نمی شود، ولی در صورتیکه برای اکران جلوه قبل از اعمال و در مرحله پیشاکران لیآوت مصرف شود بسیار طراحی اپلیکیشن در مشهد اثر گذار خواهد بود.
این ویژگیها را روی لیآوت contact_item.xml که طرحبندی مورد منفرد مخاطبین را در نرم افزار Contacts+ ما تعریف و تمجید مینماید آزمون می کنیم. درپی میتوانید پیشاکران و کد پیشاکران کنونی این طرحبندی را ملاحظه کنید:
1
2 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:app="http://schemas.android.com/apk/res-auto"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:id="@+id/contact_card_view"
7 android:layout_gravity="center"
8 android:layout_width="match_parent"
9 android:layout_height="wrap_content"
10 app:cardCornerRadius="9dp"
11 android:clickable="true"
12 android:focusable="true"
13 app:cardElevation="3dp"
14 android:padding="16dp"
15 app:cardUseCompatPadding="true"
16 android:foreground="?attr/selectableItemBackground">
17
18 19 android:layout_width="match_parent"
20 android:layout_height="wrap_content"
21 android:layout_margin="8dp">
22
23 24 android:id="@+id/avatar_image"
25 android:layout_width="38dp"
26 android:layout_height="38dp"
27 android:contentDescription="User avatar"
28 android:scaleType="centerCrop"
29 tools:src="@drawable/ic_face_male"
30 app:layout_constraintTop_toTopOf="parent"
31 android:layout_marginLeft="8dp"
32 android:layout_marginStart="8dp"
33 app:layout_constraintLeft_toLeftOf="parent"
34 tools:ignore="HardcodedText"/>
35
36 37 android:id="@+id/contact_name_textview"
38 android:layout_width="wrap_content"
39 android:layout_height="wrap_content"
40 android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
41 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
42 android:layout_marginLeft="8dp"
43 android:layout_marginStart="8dp"
44 tools:text="John Doe"
45 app:layout_constraintTop_toTopOf="parent"/>
46
47 48 android:id="@+id/contact_mobile_number_static_textview"
49 android:layout_width="wrap_content"
50 android:layout_height="wrap_content"
51 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
52 android:textColor="@color/colorSecondaryText"
53 android:text="@string/mobile_number_static_text"
54 android:layout_marginTop="8dp"
55 app:layout_constraintTop_toBottomOf="@+id/contact_name_textview"
56 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
57 android:layout_marginLeft="8dp"
58 android:layout_marginStart="8dp"/>
59
60 61 android:id="@+id/contact_mobile_number_textview"
62 android:layout_width="wrap_content"
63 android:layout_height="16dp"
64 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
65 android:textColor="@color/colorSecondaryText"
66 tools:text="(800) 555-7150"
67 android:layout_marginTop="8dp"
68 app:layout_constraintTop_toBottomOf="@+id/contact_name_textview"
69 app:layout_constraintLeft_toRightOf="@+id/contact_mobile_number_static_textview"
70 android:layout_marginLeft="@dimen/contact_item_static_textview_margin"
71 android:layout_marginStart="@dimen/contact_item_static_textview_margin"/>
72
73 74 android:id="@+id/contact_home_number_static_textview"
75 android:layout_width="wrap_content"
76 android:layout_height="wrap_content"
77 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
78 android:textColor="@color/colorSecondaryText"
79 android:text="@string/home_number_static_text"
80 android:layout_marginTop="8dp"
81 app:layout_constraintTop_toBottomOf="@+id/contact_mobile_number_static_textview"
82 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
83 android:layout_marginLeft="8dp"
84 android:layout_marginStart="8dp"/>
85
86 87 android:id="@+id/contact_home_number_textview"
88 android:layout_width="wrap_content"
89 android:layout_height="wrap_content"
90 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
91 android:textColor="@color/colorSecondaryText"
92 tools:text="(800) 555-7150"
93 android:layout_marginTop="8dp"
94 app:layout_constraintTop_toBottomOf="@+id/contact_mobile_number_textview"
95 app:layout_constraintLeft_toRightOf="@+id/contact_home_number_static_textview"
96 android:layout_marginLeft="8dp"
97 android:layout_marginStart="8dp"/>
98
99 100 android:id="@+id/contact_office_number_static_textview"
101 android:layout_width="wrap_content"
102 android:layout_height="wrap_content"
103 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
104 android:textColor="@color/colorSecondaryText"
105 android:text="@string/office_number_static_text"
106 android:layout_marginTop="8dp"
107 app:layout_constraintTop_toBottomOf="@+id/contact_home_number_textview"
108 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
109 android:layout_marginLeft="8dp"
110 android:layout_marginStart="8dp"/>
111
112 113 android:id="@+id/contact_office_number_textview"
114 android:layout_width="wrap_content"
115 android:layout_height="wrap_content"
116 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
117 android:textColor="@color/colorSecondaryText"
118 tools:text="(800) 555-7150"
119 android:layout_marginTop="8dp"
120 app:layout_constraintTop_toBottomOf="@+id/contact_home_number_textview"
121 app:layout_constraintLeft_toRightOf="@+id/contact_office_number_static_textview"
122 android:layout_marginLeft="8dp"
123 android:layout_marginStart="8dp"/>
124
125 126 android:id="@+id/contact_email_static_textview"
127 android:layout_width="wrap_content"
128 android:layout_height="wrap_content"
129 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
130 android:textColor="@color/colorSecondaryText"
131 android:text="@string/email_static_text"
132 android:layout_marginTop="8dp"
133 app:layout_constraintTop_toBottomOf="@+id/contact_office_number_static_textview"
134 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
135 android:layout_marginLeft="8dp"
136 android:layout_marginStart="8dp"/>
137
138 139 android:id="@+id/contact_email_textview"
140 android:layout_width="wrap_content"
141 android:layout_height="wrap_content"
142 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
143 android:textColor="@color/colorSecondaryText"
144 tools:text="john.doe@mail.com"
145 android:layout_marginTop="8dp"
146 app:layout_constraintTop_toBottomOf="@+id/contact_office_number_textview"
147 app:layout_constraintLeft_toRightOf="@+id/contact_email_static_textview"
148 android:layout_marginLeft="8dp"
149 android:layout_marginStart="8dp"/>
150
151 152 android:id="@+id/contact_address_static_textview"
153 android:layout_width="wrap_content"
154 android:layout_height="wrap_content"
155 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
156 android:textColor="@color/colorSecondaryText"
157 android:text="@string/address_static_text"
158 android:layout_marginTop="8dp"
159 app:layout_constraintTop_toBottomOf="@+id/contact_email_static_textview"
160 app:layout_constraintLeft_toRightOf="@+id/avatar_image"
161 android:layout_marginLeft="8dp"
162 android:layout_marginStart="8dp"/>
163
164 165 android:id="@+id/contact_address_textview"
166 android:layout_width="wrap_content"
167 android:layout_height="wrap_content"
168 android:textAppearance="@style/TextAppearance.AppCompat.Body1"
169 android:textColor="@color/colorSecondaryText"
170 tools:text="San-Fransisco, US"
171 android:layout_marginTop="8dp"
172 app:layout_constraintTop_toBottomOf="@+id/contact_email_textview"
173 app:layout_constraintLeft_toRightOf="@+id/contact_address_static_textview"
174 android:layout_marginLeft="8dp"
175 android:layout_marginStart="8dp"/>
176
177 178 android:id="@+id/favourite_button"
179 android:layout_width="38dp"
180 android:layout_height="38dp"
181 android:src="@drawable/ic_star_empty_green"
182 android:background="?selectableItemBackground"
183 android:layout_marginRight="4dp"
184 android:layout_marginEnd="4dp"
185 app:layout_constraintRight_toLeftOf="@+id/divider_line"
186 app:layout_constraintTop_toTopOf="parent"
187 android:layout_marginLeft="8dp"
188 android:layout_marginStart="8dp"/>
189
190 191 android:id="@+id/divider_line"
192 android:layout_height="38dp"
193 android:layout_width="1dp"
194 android:background="@color/colorSecondaryText"
195 android:layout_marginStart="4dp"
196 android:layout_marginLeft="4dp"
197 app:layout_constraintTop_toTopOf="parent"
198 app:layout_constraintRight_toLeftOf="@+id/call_button"
199 android:layout_marginRight="@dimen/contact_item_divider_margin"
200 android:layout_marginEnd="@dimen/contact_item_divider_margin"/>
201
202 203 android:id="@+id/call_button"
204 android:layout_width="38dp"
205 android:layout_height="38dp"
206 android:src="@drawable/ic_phone"
207 android:background="?selectableItemBackground"
208 android:layout_marginRight="8dp"
209 android:layout_marginEnd="8dp"
210 app:layout_constraintRight_toRightOf="parent"
211 app:layout_constraintTop_toTopOf="parent"
212 android:layout_marginStart="4dp"
213 android:layout_marginLeft="4dp"/>
214
215
216
217
مشاهده بی نقص کدها
به ویژگیهای tools:text در موادتشکیل دهنده و ویژگی tools:src در عنصر اعتنا نمائید. ما بهاین جهت از این ویژگی به کار گیری می کنیم که هم دادهها در طول مجال انجام از دیتابیس یا این که API بازیابی می شوند و هم در موادسازنده View مرتبط اکران پیدا مینمایند. فارغ از به کارگیری از ویژگیهای tools مورد کارت ما چیزی مانند تحت خواهد بود:
این حالت پاره ای سردرگم کننده میباشد. استعمال از ویژگیهای با پیشوند :tools قابلیت بصریسازی دادهها را در پیشاکران لیآوت در مشت ما قرار میدهند و خواهیم توانست این طرحبندی را با تمرکز بیشتری آزمایش کنیم.
همینطور خواهیم توانست از ویژگیهای با پیشوند :tools برای حذف یک ویژگی با پیشوند :android فقط از پیشاکران لیآوت استعمال کنیم. برای مثال فرض نمائید که میخواهیم موردهای مخاطبان ما فقط اسم و شماره یاور کاربر را اکران دهند و داده ها دیگر را در طی کلیک کردن مخاطب به اکران بگذارند. برای فعال سازی این قابلیت و امکان کافی میباشد طول را روی 80dp تهیه کنیم و مستمع onClick را طوری اضافه کنیم که داده ها ثانویه را گشوده نماید.
چنان که میبینید بعد از گزینش طول روی 80dp دیگر توانا به دیدن فیلدهای ثانویه در پیشاکران لیآوت نیستیم. البته حل این ایراد بسیار بی آلایش میباشد. کافی میباشد "tools:layout_height=”wrap_content را به اضافه کنیم. این حالت بدان مفهوم نیز است که قابلیت به کار گیری از هر دو ویژگی فضای اسم :android و ویژگیهای مطابقت و همخوانی :tools هم زمان روی یک عنصر view وجود داراست.
tools:context
این ویژگی گزینش مینماید کهاین لیآوت به صورت پیشفرض با کدام کار مرتبط میباشد. بنابراین قابلیت و امکانهایی مانند تعیین پوسته مطلوب برای اکران یک لیآوت، رندر کردن نوار اکشن، جایی برای اضافه کردن دستگیرههای onClick و مواقعی از این دست در ادیتور یا این که پیشاکران لیآوت فعال می شوند که مستلزم استحضار از اکتیویتی میباشند.
در نمونه نرم افزار مخاطبان، این ویژگی را به تگ ریشه فرگمان مخاطبان خویش افزودیم، البته بهاین فرگمان استحضار دهیم که در اکتیویتی اساسی اضافه گردد.
1 2 xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 tools:context=".ui.activity.MainActivity">
tools:layout
این ویژگی فقط از سوی تگهای استعمال میگردد و به ادیتور راجعبه لیآوتی که می بایست از سوی پیشاکران لیآوت، باطن فرگمان ترسیم خواهد شد اگاهی می دهد. پیرو تفاوت در میان پیشاکرانهای لیآوت پوشه activity_main.xml را پیش و بعداز اضافه کردن عبارت "tools:layout=”@layout/fragment_contacts به تگ می بینید:
1
2 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:app="http://schemas.android.com/apk/res-auto"
5 xmlns:tools="http://schemas.android.com/tools"
6 android:layout_width="match_parent"
7 android:layout_height="match_parent"
8 tools:context=".ui.activity.MainActivity">
9
10 11 android:layout_width="match_parent"
12 android:layout_height="wrap_content"
13 android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
14
15 16 android:id="@+id/toolbar"
17 android:layout_width="match_parent"
18 android:layout_height="?attr/actionBarSize"
19 app:layout_scrollFlags="scroll|enterAlways"
20 app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
21
22 23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:text="Contacts+"
26 android:textStyle="bold"
27 android:textSize="18sp"/>
28
29
30
31
32
33 34 android:id="@+id/home_fragment_container"
35 android:layout_width="match_parent"
36 android:layout_height="match_parent"
37 app:layout_behavior="@string/appbar_scrolling_view_behavior"
38 tools:layout="@layout/fragment_contacts"/>
39
40
مشاهده بی نقص کدها
tools:showIn
این ویژگی برای اشاره به یک لیآوت استعمال میگردد که از این لیآوت تحت عنوان یک include به کارگیری مینماید و از روش تگ به آن اشاره مینماید. این موقعیت به ما قابلیت می دهد که فولدر را چنان که در طی جاسازی در لیآوت والد خویش چشم میگردد ببینیم و بازنویسی کنیم. برای مثال اضافه کردن "tools:showIn=”@layout/activity_main به تگ ریشه پوشه contact_item.xml موجب میگردد که ادیتور لیآوت مارا باطن اکتیویتی اساسی از جدید ترسیم نماید:
tools:listitem | tools:listheader | tools:listfooter
این ویژگیها برای و زیرکلاسهای آن مانند و به کار گیری می شوند و کاربردشان انتخاب لیآوتی میباشد که بایستی باطن آن آداپتر به طور یک مورد لیست، هدر یا این که فوتر ترسیم خواهد شد. از جمله لیآوت fragment_contacts_xml در نرم افزار +Contacts ما یک اعلان مینماید که پیش و بعد از اضافه کردن "tools:listitem=”@layout/contact_item به طور تحت میباشد:
1
2 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:tools="http://schemas.android.com/tools"
5 xmlns:app="http://schemas.android.com/apk/res-auto"
6 android:id="@+id/contact_fragment_relative_layout"
7 android:layout_width="match_parent"
8 android:layout_height="match_parent"
9 tools:context=".ui.activity.MainActivity"
10 tools:showIn="@layout/activity_main">
11
12 13 android:id="@+id/recyclerview_contacts"
14 android:layout_width="match_parent"
15 android:layout_height="wrap_content"
16 android:gravity="center"
17 android:visibility="visible"
18 app:layoutManager="LinearLayoutManager"
19 tools:listitem="@layout/contact_item"/>
20
21
مشاهده بی نقص کدها
tools:itemCount
این ویژگی تنهاً برای به کارگیری می شود و جهت گزینش تعداد گزینههای لیست که ادیتور لیآوت بایستی در پیشاکران لیآوت رندر کردن آیتم به کارگیری قرار می گیرد.
مطابق مشاهدات ما اندروید استودیو به طور پیشفرض 10 گزینه لیست را برای اکران میدهد. از این رو به طور معمول با اضافه کردن ویژگی، تمام شیت لیآوت را پوشش می دهد و دیگر نمیقدرت موادسازنده تحت آن را روئت کرد. دراین مواقعی ویژگی tools:itemCount به ما امداد مینماید که موادتشکیل دهنده ذیل را ببینیم.

راهکارهای کاهش CPC در کمپینها