android - 在 ScrollView 中使用表格布局

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

你好,我是安卓新手
我试图使用 ScrollView ,在互联网上的某个地方我找到了这段代码

<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">?如果我将 stretchColumns="1" 更改为 "3" 或任何我没有得到的数字我的 ScrollView 中的任何更改。

最佳答案

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

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

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

详情请访问

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"/>

关于android - 在 ScrollView 中使用表格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42993392/

相关文章:

android - 将 arraylist 从 servlet 发送到 Android 应用程序

android - 如何在android中释放内存以避免内存泄漏

android - 自定义形状的 Linearlayout 在 android 中具有弯曲的一面

android - RadioGroup 中的自定义 RadioButton 没有独占选择

java - 如何用 JodaTime 表示 'time'

android - 在冲突替换上创建唯一约束

android - 如何在 android 中制作类似 google io 2014 应用程序的 ListView ?

android - 在主要 Activity 中执行 searchView 时遇到问题(不是操作栏)

android - 使用 LinearLayout 和权重更改可见性

Android 文件提供程序非法参数异常