Android TableLayout问题:获得固定宽度的右列?
(编辑:我比以前更进一步了)
我一直在尝试获得一个简单的 2 列 TableLayout,我的左列中有一个 LinearLayout,我可以动态添加元素来填充除了固定的 100px 右列之外,水平空间向上。
到目前为止,如果 LinearLayout 包含多个元素,这对我有用。如果它只包含一个元素,则右列被推出到屏幕右侧
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@layout/main">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.4"
android:orientation="vertical"></LinearLayout>
<com.epaga.ArcDrawableView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right" android:layout_weight="0.1" >
</com.epaga.ArcDrawableView>
</TableRow>
</TableLayout>
</ScrollView>
我尝试过的事情:
- 将可绘制视图(应该是固定列)更改为
android:layout_width="150px"
- 将
stretchcolumns
设置更改为 0。 - 将左侧列的
layout_width
更改为 fill_parent(将右侧列推离屏幕)或wrap_content(折叠左侧列) )
有什么想法吗?
(Edited: I'm one step further than before)
I've been trying to get a simple 2-column TableLayout going where I have a LinearLayout in my left column that I dynamically add elements to which fills up the horizontal space except for the fixed 100px right column.
Here's what I have so far which works for me IF the LinearLayout contains more than one element. If it contains only one element, the right column is pushed out to the right of the screen
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@layout/main">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.4"
android:orientation="vertical"></LinearLayout>
<com.epaga.ArcDrawableView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right" android:layout_weight="0.1" >
</com.epaga.ArcDrawableView>
</TableRow>
</TableLayout>
</ScrollView>
Things I've tried:
- changing the drawable view (which is supposed to be the fixed column) to
android:layout_width="150px"
- changing the
stretchcolumns
setting to 0. - changing the left columns'
layout_width
to either fill_parent (pushes the right column off the screen) or wrap_content (collapses the left column)
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,为什么要使用
TableLayout
?为什么不直接使用嵌套的LinearLayouts?您已经决定不关心TableLayout
的主要用途(自动计算列大小),因为您正在尝试自己修复列大小。其次,您可以使用右列的普通小部件而不是自定义的 View 类来使其正常工作吗?您的问题可能是由于您的自定义
View
- 我首先使用普通小部件让某些东西按照您想要的方式工作。First, why are you using a
TableLayout
? Why not just use nestedLinearLayouts
? You've already decided you don't care about the primary use for aTableLayout
-- automatic computation of column sizes -- because you're trying to fix the column sizes yourself.Second, can you get it working using an ordinary widget for the right column, rather than your custom
View
class? Your problem may be due to your customView
-- I'd start by getting something working the way you want using ordinary widgets.