Skip to main content

Vincent Tsao's Library tagged layout   View Popular, Search in Google

Aug
10
2010

  • 按我理解,layout_gravity 属性是用于设置View 与其容器的对齐关系的,但实际使用中 却发现 似乎不是这样,请看如下代码:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#AA009988">
        <TextView
            android:id="@+id/my_view"
            android:layout_width="220dip"
            android:layout_height="100dip"
            android:text="sdfasdfsdfsdf\nsdfjlwjesd"
            android:background="#889900AA"
            *android:layout_gravity="center"* />
    </LinearLayout>

    我为 TextView 设置了 *layout_gravity="center"*- ,本来它应该在父容器中 垂直和水平
    居中的,但事实上只是水平居中了,垂直方向并未居中。
    我再进一步通过 *layout_gravity="**center_vertical**"* ,但仍然无法垂直居中,请问这是为什么呢?

  • 你可以在最外面的 LinearLayout 加上android:gravity="center".
    Vertical LinearLayout中, layout_gravity 设置成center无法垂直剧中,是因
    为container的排版被限制为从上到下,

    试想一下,如果按照你的逻辑,假设第一个child layout_gravity设置成bottom,  
    第二个childlayout_gravity设置成top,  那么第一个就会跑到第二个下面了。
    所以, 当你设置整个linearlayout为垂直, layout_gravity中, 只有 left,
    right, center_ horizontal 管用的。

    tj

Apr
12
2010

  • 我看到一个最简洁的回复是(让我一直记得,哈哈):
    layout_gravity是本元素相对于父元素中的位置
    gravity是本元素中内容相对自己的位置
May
5
2009

  • android:id="@+id/my_button"
  • The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file). There are a number of other ID resources that are offered by the Android framework
  • 1 more annotation(s)...
Feb
25
2007

  • 对于一个左中右3栏布局的页面,比如home.donews.com,用户最想看到的是中栏的信息
  • <script language="javascript">
    var l=document.getElementById("left").scrollHeight
    var m=document.getElementById("middle").scrollHeight
    var r=document.getElementById("right").scrollHeight
    layoutHeight=Math.max(l,m,r)
    document.getElementById("left").style.height=layoutHeight+"px"
    document.getElementById("right").style.height=layoutHeight+"px"
    document.getElementById("middle").style.height=layoutHeight+"px"
    </script>
  • 1 more annotation(s)...
1 - 11 of 11
Showing 20 items per page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo
Move to top