Android TableLayout问题:获得固定宽度的右列?

发布于 2024-08-23 09:38:42 字数 1487 浏览 6 评论 0原文

编辑:我比以前更进一步了

我一直在尝试获得一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最舍不得你 2024-08-30 09:38:43

有什么想法吗?

首先,为什么要使用 TableLayout?为什么不直接使用嵌套的LinearLayouts?您已经决定不关心 TableLayout 的主要用途(自动计算列大小),因为您正在尝试自己修复列大小。

其次,您可以使用右列的普通小部件而不是自定义的 View 类来使其正常工作吗?您的问题可能是由于您的自定义View - 我首先使用普通小部件让某些东西按照您想要的方式工作。

Any thoughts?

First, why are you using a TableLayout? Why not just use nested LinearLayouts? You've already decided you don't care about the primary use for a TableLayout -- 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 custom View -- I'd start by getting something working the way you want using ordinary widgets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文