zoukankan      html  css  js  c++  java
  • 建一个简单的用户界面

    Create a Linear Layout(创建一个线性布局)

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    </LinearLayout>

    注释:android:orientation="vertical"水平线性布局,"horizontal"垂直水平线性

          match_parent:This value declares that the view should expand its width or height to match the width or height of the parent view.

    Add a Text Field(添加一个text)

    To create a user-editable text field, add an <EditText> element inside the <LinearLayout>

     <EditText android:id="@+id/edit_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message" />

    Add String Resources

    •     String resources allow you to manage all UI text in a single location, which makes it easier to find and update text.
    •     默认情况下string resource 文件位于t res/values/strings.xml.

       The result for strings.xml looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">My First App</string>
        <string name="edit_message">Enter a message</string>
        <string name="button_send">Send</string>
        <string name="action_settings">Settings</string>
        <string name="title_activity_main">MainActivity</string>
    </resources>

    Add a Button

     <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_send" />
    • The height and width are set to "wrap_content" so the button is only as big as necessary to fit the button's text.
    • This button doesn't need the android:id attribute, because it won't be referenced from the activity code.

    Make the Input Box Fill in the Screen Width

    The layout is currently designed so that both the EditText and Button widgets are only as big as necessary to fit their content, as shown in figure

    Figure 2. The EditText and Button widgets have their widths set to "wrap_content".

    • weight表示横向占比:如果有两个view(分别为view1,view2),view1的weight值设为2,view2的weight值设为1,那么view1占2/3,view2占1/3;
    • weight的默认值为0,所以如果在多个views中只设置一个weight值为1,其他均为0,那么weight值设为1的那个view会占全其他空间。
    • Here’s how your complete layout file should now look:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal">
          <EditText android:id="@+id/edit_message"
              android:layout_weight="1"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:hint="@string/edit_message" />
          <Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/button_send" />
      </LinearLayout>
       
  • 相关阅读:
    一例千万级pv高性能高并发网站架构[原创]
    Download SymmetricDS Data Sync Software for Free
    阿里巴巴开源项目:分布式数据库同步系统otter(解决中美异地机房)
    青云QingCloud业内率先支持云端全面透明代理功能 | SDNLAB | 专注网络创新技术
    UCloud EIP 你真的懂得如何使用么?
    MySQL高可用性大杀器之MHA | 火丁笔记
    Zookeeper、Solr和Tomcat安装配置实践
    Best Premium Private Proxy Service | Lime Proxies
    突破LVS瓶颈,LVS Cluster部署(OSPF + LVS)
    Nodejs负载均衡:haproxy,slb以及node-slb
  • 原文地址:https://www.cnblogs.com/me1105/p/4311714.html
Copyright © 2011-2022 走看看