当前位置: 首页 > news >正文

网站备案失败/网络热词大全

网站备案失败,网络热词大全,响应式网站建设信息,做网站视频 上传到哪儿关注微信号:javalearns 随时随地学Java 或扫一扫 随时随地学Java 1. 一些常用的公共属性介绍 1) layout_width - 宽fill_parent: 宽度和父元素相同,wrap_content: 宽度随本身的内容所调整,或者指定 px 值来设置宽2) layout_height - 高fill…

关注微信号:javalearns   随时随地学Java

或扫一扫

随时随地学Java

1. 一些常用的公共属性介绍

1) layout_width - 宽
fill_parent: 宽度和父元素相同,wrap_content: 宽度随本身的内容所调整,或者指定 px 值来设置宽
2) layout_height - 高
fill_parent: 高度和父元素相同,wrap_content: 高度随本身的内容所调整,或者指定 px 值来设置高
3) background - 设置背景图
4) padding - 设置边距
可以具体设置paddingBottom,paddingLeft,paddingRight,paddingTop来设定不同的px值
5) id - 该object的id号
@+id/id1 代表添加新的id名为id1, @id/id1 代表引用id1的控件
6) layout_weight - 重要度
个人理解为显示的优先级。默认为0(最高),数值越大,优先级越低!参考下面的Linear Layout例子。要让layout_weight生效,需要父层或父父层的相应layout_width/layout_height = "fill_parent",否则wrap_content会压缩到最小足够空间!
7) layout_gravity - Container组件的对齐方式
组件在layout里面的对齐方式。
8) gravity - 文字在组件里的对齐方式
例如设置button里面的文字在button中居中显示。
* 大多数属性是可以调用对应的函数来动态改变状态的,请查看SDK Doc。

2. Linear Layout 线形布局

orientation - 容器内元素的排列方式。vertical: 子元素们垂直排列,horizontal: 子元素们水平排列。在代码里可通过setOrientation()进行动态改变,值分别为HORIZONTAL或者VERTICAL。
* 在Linear Layout,  宽度/高度都是按着组件的次序逐个占用的!所以当某个组件设置"fill_parent",在没有设置Layout_weight的情况下,该组件会占用了余下的空间,那么在它后面的组件就会显示不出来。如下图的EditText如果没有设置android:layout_weight="1", 它下面的其他组件就看不见了!
baselineAligned 一般情况下,这个属性默认为true,代表在同一方向的组件都基于第一个组件对齐。所以可以看到下图的text1, button1, text2是在同一水平线的。当不需要这效果时,可以设置为false。
可以参考官方网页http://androidappdocs.appspot.com/resources/tutorials/views/hello-linearlayout.html。

LinearLayout

 xml代码:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:orientation="vertical" 
  4.     android:layout_width="fill_parent" 
  5.     android:layout_height="fill_parent" > 
  6.  
  7.     <TextView 
  8.         android:text="@string/hello" 
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content"  
  11.         /> 
  12.     <EditText 
  13.         android:layout_width="fill_parent" 
  14.         android:layout_height="wrap_content" 
  15.         android:layout_weight="1" 
  16.         android:id="@+id/edittext" 
  17.         /> 
  18.  
  19.     <LinearLayout 
  20.         android:id="@+id/LinearLayout01"  
  21.         android:layout_width="fill_parent"  
  22.         android:layout_height="wrap_content"  
  23.         android:orientation="horizontal"> 
  24.         <TextView  
  25.             android:text="text1"  
  26.             android:id="@+id/TextView01"  
  27.             android:layout_width="wrap_content"  
  28.             android:layout_height="wrap_content" 
  29.             /> 
  30.         <Button android:text="Button01"  
  31.             android:id="@+id/Button01"  
  32.             android:layout_width="fill_parent"  
  33.             android:layout_height="wrap_content" 
  34.             android:layout_weight="1" 
  35.             /> 
  36.         <TextView  
  37.             android:text="text2"  
  38.             android:id="@+id/TextView02"  
  39.             android:layout_width="wrap_content"  
  40.             android:layout_height="wrap_content" 
  41.             /> 
  42.     </LinearLayout> 
  43.  
  44.     <TextView 
  45.         android:layout_width="wrap_content" 
  46.         android:layout_height="wrap_content" 
  47.         android:text="buttom" 
  48.         /> 
  49.  
  50. </LinearLayout> 

3. RelativeLayout  相对定位布局

这个布局比较易懂,但组件间容易存在依赖关系,“牵一发而动全身“,所以在确定组件间布局关系不会再变动时,可以考虑采用!先看看xml代码:
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <RelativeLayout 
  3.   xmlns:android="http://schemas.android.com/apk/res/android" 
  4.   android:layout_width="wrap_content" 
  5.   android:layout_height="wrap_content" 
  6.   android:id="@+id/relativelayout"> 
  7.  
  8.     <ImageView 
  9.         android:id="@+id/image" 
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content" 
  12.         android:src="@drawable/icon" 
  13.         /> 
  14.     <TextView 
  15.         android:id="@+id/text1" 
  16.         android:layout_width="fill_parent" 
  17.         android:layout_height="wrap_content" 
  18.         android:text="@string/hello" 
  19.         android:layout_toRightOf="@id/image" 
  20.         /> 
  21.     <Button 
  22.         android:id="@+id/button1" 
  23.         android:layout_width="fill_parent" 
  24.         android:layout_height="wrap_content" 
  25.         android:text="button1" 
  26.         android:layout_toRightOf="@id/image" 
  27.         android:layout_below="@id/text1" 
  28.         /> 
  29. </RelativeLayout> 
Java代码(动态添加组件):
  1. public class RelativeDemo extends Activity { 
  2.  
  3.     @Override 
  4.     public void onCreate(Bundle savedInstanceState) { 
  5.         super.onCreate(savedInstanceState); 
  6.         setContentView(R.layout.relative); 
  7.  
  8.         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( 
  9.             ViewGroup.LayoutParams.FILL_PARENT, //width 
  10.             ViewGroup.LayoutParams.WRAP_CONTENT //height 
  11.         ); 
  12.  
  13.         //设置editText layout_below="@id/button1" 
  14.         lp.addRule(RelativeLayout.BELOW, R.id.button1); 
  15.  
  16.         //设置editText layout_alignLeft="@id/image" 
  17.         lp.addRule(RelativeLayout.ALIGN_LEFT, R.id.image); 
  18.  
  19.         ((RelativeLayout) findViewById(R.id.relativelayout)).addView(
  20.         new EditText(this), lp); 
  21.     } 
效果图:

RelativeLayout

先添加参照物(ImageView),然后就可以依次添加其他组件,定义位置规则rule!位置规则是不分先后的!另外ADT插件提供的预览图,有时候是不准的,未能及时更新,所以最好还是要到模拟器上测试!
RelativeLayout的xml属性很多,总的来说分为2类:
1) 要指定参照物的,layout_alignBottom,layout_toLeftOf,layout_above,layout_alignBaseline系列的;
layout_above = ”@id/text1“
2) 以parent为参照物,设置true/false,layout_centerVertical,layout_alignParentLeft系列的。
layout_alignParentLeft = ”true“
其中layout_alignWithParentIfMissing是比较有用且要注意的属性,当设置为true,在指定的参照物找不到的情况下,会使用parent作为新的参照物!
 RelativeLayout.LayoutParams是用于设置位置规则的。上述的xml属性均来自此静态类。但它的AddRule(int verb, int anchor),参数的verb动作却是引用RelativeLayout的常量,而这些常量和部分xml属性相对应。参数anchor的值可能是参照物的id,RelativeLayout.TRUE,-1(当不需要指定anchor的verb)。可以这样理解verb和anchor:
xml属性 (verb) = "value" (anchor)
其中它的构造函数之一: RelativeLayout.LayoutParams(int w, int h),参数指定所要设置子View的宽度和高度。

关注微信号:javalearns   随时随地学Java

或扫一扫

随时随地学Java


http://www.jmfq.cn/news/4775959.html

相关文章:

  • 公司做网站需要注意什么/百色seo快速排名
  • 深圳微信网站开发/windows优化大师自动安装
  • 芜湖网站建设优化/百度贴吧网页版登录入口
  • 望京 网站开发/各大网站提交入口
  • b2b外贸网站大全/江苏网站推广
  • 长春哪里做网站/百度问问
  • 银川网站建设公司哪家好/西安seo引擎搜索优化
  • 企业大型网站开发/广州谷歌seo公司
  • 建销售网站需要多少钱/附近成人电脑培训班
  • 菏泽 网站建设/合肥网站制作推广
  • 山西做杂粮的网站/网络营销考试题目及答案2022
  • 专业做网站开发费用/网站seo设计方案案例
  • 推广文案是什么/南昌seo报价
  • 建设网站比较好的公司排名/游戏推广合作平台
  • 网站主机在哪里注册呢/厦门关键词优化seo
  • 常用的网站建设程序有哪些/新浪网今日乌鲁木齐新闻
  • 直播网站 建设/网络推广工作好吗
  • 帮人做网站/有别人的交易链接怎么交易
  • 色弱做网站/合肥seo网站建设
  • 做网站域名优化的怎么样/全网推广成功再收费
  • 福田祥菱v3报价及图片/北京培训seo哪个好
  • 网站模板免费/steam交易链接在哪里看
  • 济南网站推广¥做下拉去118cr/怎么制作一个网页
  • 青山做网站/微信小程序开发文档
  • 高州网站建设/seo技术平台
  • 虚拟机中做网站/泉州百度推广排名优化
  • 网站增加权重/最知名的网站推广公司
  • 建站节/网站模板及源码
  • wordpress建论坛/上海百度seo牛巨微
  • 做配电柜在哪个网站发布信息/百度大全