Android 的Margin和Padding Layout_weight属性

来源:互联网 发布:js正则表达式 i 编辑:程序博客网 时间:2024/06/06 02:03


  网上这个说得比较清楚:

首先看一下Layout_weight属性的作用:它是用来分配剩余空间的一个属性,你可以设置他的权重。

http://mobile.51cto.com/abased-375428.htm

  值得注意的是,如果使用layout_weight的同时,还使用layout_height和layout_width关系属性,则有点混乱:layout_weight一般会覆盖layout_height和layout_width,但并非总是如此。与其去计算复杂的剩余空间分配。不如按照建议:

   打算使用layout_weight 属性,设置相应的高度或宽度0DP。那这样,视图分配的大小将只由layout_weight控制。


RelativeLayout容器(安卓集装箱2:RelativeLayout)

参考:http://tigerwoods.tistory.com/11

二。 RelativeLayout 

窗口小部件RelativeLayout /容器的部件的相对位置是根据该方法测定的。

首先,一个父容器控件内部确定其性质的位置如下所示。


以上所有的特性都是真,假的输入值。

其次,相对于窗口小部件/容器位于相对于所述特性在使用过程如下。


最新的android:layout_alignBaseline基于文本的,比如标签和EditText上的字母的AIR插件matchuneunde有用的高度。

以上所有都是相对的属性窗口小部件/容器的基础上,应指定为id的值。

相对于标准的“@ ID /控件ID”小部件的id是确定的。

例如,一个部件一个是机器人:ID =“@ + ID / A”如果你有identiy XML中的控件A“@ ID / A”里面被调用。

部件部件B,则位于右侧的窗口小部件的A和B要指定用于对齐的下列属性。

<小部件的 

......

机器人:ID =“@ + ID / A”/>

<B小工具

...... 

机器人:layout_alignRightOf =“@ ID / A”/>

如果部件是A,B被放置在下面的表格。

请注意,在RelativeLayout两点:

  • XML布局文件进行解析从顶部标识为一个位于下方的XML munseosang部件位于小部件引用的id是不可能的底部顺序。 (尚未宣告为不能低于引用的变量。)
  • 在所有比自己其他的相关属性和填充剩余空间时,只适用于小部件。

RelativeLayout例子(main.xml中)

结果如下。



layout、layout-land和layout-port的区别

 一般把UI 布局文件放在layout文件夹下,如果要支持橫屏,就会取同名的layout放在layout-land文件夹下。

-res/layout-land 横屏  -res/layout-port 竖屏  -res/layout 默认

引自:http://www.cnblogs.com/error404/archive/2011/11/30/2269177.html

How to Support Multiple Screens

Provide different bitmap drawables for different screen densities

The configuration qualifiers you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi(high), and xhdpi (extra high). For example, bitmaps for high-density screens should go in drawable-hdpi/.

参考:http://developer.android.com/guide/practices/screens_support.html


android:fillViewport

用法例子:http://qiansheep.blog.163.com/blog/static/3506872020129942029990/

当你想让一个高度值不足scrollview的子控件fillparent的时候,单独的定义 android:layout_height="fill_parent"是不起作用的,必须加上fillviewport属性,当子控件的高度值大于 scrollview的高度时,这个标签就没有任何意义了。

代码如下:
<?xml version="1.0" encoding="utf-8"?> 
<!-- 背景:蓝色 --> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#0000ff" > 
 
    <!-- 背景:绿色 --> 
 
    <LinearLayout 
        android:id="@+id/linearLayout1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="#00ff00" > 
 
        <TextView 
            android:id="@+id/textView1" 
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent" 
            android:layout_weight="1" 
            android:text="Hello Android." > 
        </TextView> 
    </LinearLayout> 
 
</ScrollView> 

效果图如下:

scrollView的fillviewport - qiansheep - qiansheep的博客

 尽管已经设置了android:layout_height="fill_parent",但是,整个LinearLayout和TextView还是不能充满整个屏幕。

解决办法:

在ScrollView中添加一个android:fillViewport="true"属性就可以了。顾名思义,这个属性允许ScrollView中的组件去充满它。


修改后的效果图:
scrollView的fillviewport - qiansheep - qiansheep的博客
 



0 0
原创粉丝点击