比例行大小与1固定行
在Android中,我试图基本上创建一个2行的表,其中1行是10像素,另一个需要其余的屏幕。在Silverlight中,这相当于有两行的表格,一个在“Auto”上,另一个在“*”上。比例行大小与1固定行
有没有办法做到这一点?我一直在玩布局重量,但这总是一个百分比,我想1行是固定大小(基本上wrap_content)。
任何想法?
编辑: 我试过什么建议,但它没有工作..所以我想第一行占用整个空间,除了第2行占用。第2行由两个并排的按钮组成,第1行只是一个ListView。以下是我有:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:background="#FF0000">
<ListView android:id="@+id/edit_group_listView"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0" android:background="#FFFF00">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="50dip" android:stretchColumns="2">
<TableRow>
<Button android:text="@string/button_save" android:id="@+id/edit_group_save"
android:layout_width="150dip" android:layout_height="50dip"
android:enabled="false" android:layout_column="1"></Button>
<Button android:text="@string/button_cancel" android:id="@+id/edit_group_cancel"
android:layout_width="150dip" android:layout_height="50dip"
android:layout_column="3"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
当我看到这一切我看到的是黄色的LinearLayout(按钮),没有列表视图可言。该列表视图有50个项目,我可以通过将其从此设置中删除来确认它是否可见。
好了,所以其实我想通了这一点通过审查什么Taranasus写道,这是精确到度。
这是最后的XML工作:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:background="#FF0000">
<ListView android:id="@+id/edit_group_listView"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:background="#FFFF00">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="50dip" android:stretchColumns="2">
<TableRow>
<Button android:text="@string/button_save" android:id="@+id/edit_group_save"
android:layout_width="150dip" android:layout_height="50dip"
android:enabled="false" android:layout_column="1"></Button>
<Button android:text="@string/button_cancel" android:id="@+id/edit_group_cancel"
android:layout_width="150dip" android:layout_height="50dip"
android:layout_column="3"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
这个网站还帮助:http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/
的问题,表示: 1.取向必须是“垂直“,根据文档,这实际上没有意义。 2。第二行(固定的)必须有wrap_content的高度,这也是没有意义的,因为谷歌关于权重的文档特别指出这两个元素应该是fill_parent。
是的,其实很简单。
第一个单元的权重必须为0.第二个单元的权重必须为1,并按宽度填充父级。这样它将占用它所在容器内的重新装修空间。
简单!以下是为您提供方便
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0" android:background="#FF0000">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="SomeText" android:id="@+id/theview"/>
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#FFFF00">
</LinearLayout>
</LinearLayout>
为例===================================== ==
UPDATE
让你像Crayze那样过度复杂!
首先。你不需要表格布局。
第二个问题是您将布局的两个高度都设置为fill_parrent。所以他们都在争夺屏幕尺寸。要解决这个问题,你只需要将两个布局大小都设置为wrap_content。这将工作得很好。这里有一个例子,没有你的代码表。
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:background="#FF0000">
<ListView android:id="@+id/edit_group_listView"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:background="#FFFF00">
<Button android:text="@string/button_save" android:id="@+id/edit_group_save"
android:layout_width="150dip" android:layout_height="50dip"
android:enabled="false" android:layout_column="1"></Button>
<Button android:text="@string/button_cancel" android:id="@+id/edit_group_cancel"
android:layout_width="150dip" android:layout_height="50dip"
android:layout_column="3"></Button>
</LinearLayout>
很高兴看到你解决了你的问题!不要忘了点击左边的复选标记来标记答案。 – 2011-03-25 01:21:49