Vincent Tsao's Library tagged → View Popular, Search in Google
-
按我理解,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
-
我看到一个最简洁的回复是(让我一直记得,哈哈):
layout_gravity是本元素相对于父元素中的位置
gravity是本元素中内容相对自己的位置
in list: Andriod
-
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.javafile). There are a number of other ID resources that are offered by the Android framework - 1 more annotation(s)...
-
对于一个左中右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)...
Selected Tags
Related Tags
Top Contributors
Groups interested in layout
-
Typography
All about my passion for cle...
Items: 2 | Visits: 88
Created by: Bert Deckers
-
CSS: Techniques, Tips and Tactics
A list to support the Netski...
Items: 29 | Visits: 126
Created by: Will Allen
-
WebKit and the Future of the Open Web
WebKit is an advanced HTML-C...
Items: 26 | Visits: 106
Created by: Gary Edwards
Diigo is about better ways to research, share and collaborate on information. Learn more »
Join Diigo
