官术网_书友最值得收藏!

Creating a form layout

Once you have a good wireframe to work from, you'll want to start developing the user interface screen. For this, we'll use Android Studio and its wonderful layout editor.

Since this is a brand new project, you'll need to open Android Studio and use File | New | New Project to get it started. Then, follow these steps:

  1. Name the project Claim, and leave any non-Java support turned off.
  2. Target Android 4.1 on Phone & Tablet only.
  3. In the Activity Gallery, choose the Basic Activity:
  1. Name the new Activity CaptureClaimActivity, and then change the title to Capture Claim. Leave the other parameters at their default values:
  1. Finish the New Project wizard, and wait for the project to be generated.
  2. When the project has been generated and synchronized, Android Studio will open the content_capture_claim.xml file in its layout editor.
  1. By default, Android Studio assumes that you will be using a ConstraintLayout as the root of your layout. This is an incredibly powerful and flexible tool, but also not well suited as the root element of this user interface. You'll need to switch over to the Text view at the bottom of the screen in order to change to something more suitable:
  1. The file will currently have something like the following XML in place:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.packtpub.claim.CaptureClaimActivity"
tools:showIn="@layout/activity_capture_claim">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
  1. Change the ConstraintLayout to a simple LinearLayout. LinearLayout is one of the simplest layouts available on Android. It renders each of its children in a straight line, either horizontal or vertical, depending on its orientation attribute. Replace the whole of the content_capture_claim.xml file with the following content:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.packtpub.claim.CaptureClaimActivity"
tools:showIn="@layout/activity_capture_claim">

</LinearLayout>

Choosing the right layout to use is about more than just keeping your code simple; less flexible layouts are much faster at runtime and lead to a much smoother user experience. Try to stick to simpler layouts where possible, but also avoid nesting layouts too deep (one inside the other), as this also leads to performance problems.

  1. Change back to the Design view in the layout editor, and you'll notice that the Component Tree to the left of the design view now has a LinearLayout (vertical) as its only component.
主站蜘蛛池模板: 泌阳县| 潍坊市| 依兰县| 长沙市| 吉林市| 漳浦县| 南投市| 嘉定区| 安龙县| 玛沁县| 潍坊市| 上林县| 星座| 霍州市| 甘肃省| 崇义县| 达州市| 报价| 平顺县| 泰来县| 清丰县| 浦东新区| 云安县| 辽宁省| 敖汉旗| 湘阴县| 竹北市| 兴安盟| 丹巴县| 怀柔区| 阜新市| 银川市| 远安县| 焦作市| 平乡县| 淮安市| 遵化市| 阳朔县| 额济纳旗| 温宿县| 抚远县|