设为首页 加入收藏

TOP

使用Android Studio创建LinerLayout工程
2015-11-10 13:45:56 来源: 作者: 【 】 浏览:4
Tags:使用 Android Studio 创建 LinerLayout 工程

1 创建工程


2 修改布局文件


创建工程后,res/layout下已经自动生成activity_liner_layout.xml,使用的是RelativeLayout布局。


要使用LinerLayout,需要先把RelativeLayout删除,然后添加:



从Text模式切换到Design模式,提示“Rendering Problem”,告诉你当前layout缺少那些attributes。点击提示,添加属性。


? ? android:layout_width="match_parent"
? ? android:layout_height="wrap_content">
? ?


xmlns(xml namespaces 命名空间)


添加orientation属性,该属性值包括horizontal(水平)和vertical(垂直)。这里方向设置为垂直。


android:orientation="vertical"


到这里线性布局属性已经全部设好了。


接下来该添加控件了,分别把TextView、EditText、Button、Button拖进可视化编辑器里,并修改空间的text和id。


? ? android:layout_width="wrap_content"
? ? android:layout_height="wrap_content"
? ? android:orientation="vertical">


? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="请输入"
? ? ? ? android:id="@+id/textView01" />


? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:id="@+id/editText01" />


? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="确认"
? ? ? ? android:id="@+id/button01" />


? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="取消"
? ? ? ? android:id="@+id/button02" />


在往可视化编辑器里拖的时候就可以感觉到空间只能垂直向下排列。这就是orientation属性作用的结果。


点击运行按钮,查看运行结果。



更多Android Studio相关内容可以看看以下的有用链接:?


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Weld 在 JDK 8u60 环境下的一个问.. 下一篇Linux守护进程

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: