- Mastering Android Development with Kotlin
- Milo? Vasi?
- 281字
- 2021-07-02 15:20:58
Using EditText views
We introduced the EditText views to enter editable text content. You can see some new attributes here:
- hint: This defines the default string value that will be presented to the user
- padding: This is the space between the view itself and its content
- gravity: This defines direction for the content; in our case, all text will stick to the top of the parent view
The strings resource file now looks like this:
<resources> <string name="app_name">Journaler</string> <string name="title">Title</string> <string name="your_note_content_goes_here">Your note content goes
here.</string> </resources> Todos screen will be very similar to this: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=
"http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <include layout="@layout/activity_header" /> <EditText android:id="@+id/todo_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/title" android:padding="@dimen/form_padding" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="1"> <Button android:id="@+id/pick_date" android:text="@string/pick_a_date" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" /> <Button android:id="@+id/pick_time" android:text="@string/pick_time" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" /> </LinearLayout> <EditText android:id="@+id/todo_content" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top" android:hint="@string/your_note_content_goes_here" android:padding="@dimen/form_padding" />
</LinearLayout> </ScrollView>
Again, the top container is ScrollView. Compared to the previous screen, we have introduced some differences. We added the container to hold buttons for date and time picking. The orientation is horizontal. We set the parent container attribute, weightSum, to define the weight value that can be divided by children views so each child takes the amount of space defined by its own weight. So, weightSum is one. First button has a layout_weight of 0.5. It will consume 50% of the horizontal space. The second button has the same value. We achieved view splitting in two halves. Locate the bottom of your XML and click on Design to switch to Design view. Your buttons should look like this:

We defined layouts for our screens. To express how these screens should look, we relied on many different attributes. This is just a small portion of the available attributes we can use. To make this section complete, we will present you with some other important attributes that you will use in everyday development.
- Mastering Ext JS(Second Edition)
- iOS面試一戰(zhàn)到底
- Android應(yīng)用程序開發(fā)與典型案例
- Developing Middleware in Java EE 8
- R語(yǔ)言游戲數(shù)據(jù)分析與挖掘
- 從程序員到架構(gòu)師:大數(shù)據(jù)量、緩存、高并發(fā)、微服務(wù)、多團(tuán)隊(duì)協(xié)同等核心場(chǎng)景實(shí)戰(zhàn)
- JS全書:JavaScript Web前端開發(fā)指南
- 程序員修煉之道:通向務(wù)實(shí)的最高境界(第2版)
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)案例教程
- Oracle GoldenGate 12c Implementer's Guide
- Mastering Web Application Development with AngularJS
- Python期貨量化交易實(shí)戰(zhàn)
- 零基礎(chǔ)看圖學(xué)ScratchJr:少兒趣味編程(全彩大字版)
- 現(xiàn)代CPU性能分析與優(yōu)化
- Mastering ASP.NET Core 2.0