【问题标题】:Use of Table Layout inside scroll view在滚动视图中使用表格布局
【发布时间】:2017-03-24 07:05:18
【问题描述】:

你好,我是安卓新手
我试图使用滚动视图,在互联网上的某个地方我发现了这段代码

<ScrollView 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fillViewport="true"
 android:layout_alignParentTop="true"
 android:layout_alignParentLeft="true"
 android:layout_alignParentStart="true">  
   <TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1">

这段代码完美运行,但我不明白有什么用 android:stretchColumns="1"&gt;?.如果我将stretchColumns="1"更改为"3"或任何数字,我的scroll view不会有任何变化。

【问题讨论】:

  • 你可以改用GridView
  • 欢迎来到 StackOverflow!请阅读用户指南,了解如何在发布问题之前提出好问题 (stackoverflow.com/help/how-to-ask) 谢谢
  • 谢谢你的兄弟。
  • 去吧兄弟!欢迎加入社区!!

标签: android android-layout android-xml android-scrollview android-tablelayout


【解决方案1】:

TableLayout 可以通过调用 setColumnShrinkable()(xml:android:shrinkColumns) 或 setColumnStretchable()(xml:android:stretchColumns) 将某些列指定为可收缩或可拉伸。

如果标记为可缩小,则可以缩小列宽以使表格适合其父对象。如果标记为可拉伸,它可以扩展宽度以适应任何额外的空间。

表格的总宽度由其父容器定义。请务必记住,列既可以收缩也可以拉伸。

详情请访问

https://developer.android.com/reference/android/widget/TableLayout.html

看看这个例子

<TableLayout
android:shrinkColumns="2,3"
android:stretchColumns="1,3"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

【讨论】:

  • 这很有帮助。但是当我更改 strechcolumn 时,我没有看到对滚动视图有任何影响
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
相关资源
最近更新 更多