Android train——基本组件LinearLayout、EditText、Button

LinearLayoutViewGroup的一个子类,用于放置水平或者垂直方向的子视图部件,放置方向由属性android:orientation设定。LinearLayout里的子布局按照XML里定义的顺序显示在屏幕上。

:res/layout/activity_main.xml

<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:layout_weight="1"
        android:id="@+id/edit_message"
        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>

 

当你在用户界面定义一个文本的时候,你应该把每一个文本字符串列入资源文件。这样做的好处是:对于所有字符串值,字符串资源能够单独的修改,在资源文件里你可以很容易的找到并且做出相应的修改。通过选择定义每个字符串,还允许您对不同语言本地化应用程序。

:res/values/strings.xml

<resources>
    <string name="app_name">My Application_a</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="action_settings">Settings</string>

</resources>

====>测试:

edittext_wrap

 

 这里有个权重 layout_weight注意一下

android:layout_weight="1"
posted @ 2015-07-07 15:42  cuiz_book  阅读(411)  评论(0编辑  收藏  举报