- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图让我的 TableLayout 分布在整个页面上。现在所有 TableRows 都相互“插入”。但我希望他们离得更远。
现在情况:
我想要实现的目标:
Activity.java(添加这个是因为我正在动态添加 TableRows)
public class FoundLocationsActivity extends AppCompatActivity{
int tableRows = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.foundlocations);
this.fillTable();
}
private void fillTable() {
//Get the tablelayout
TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout);
//Make the columns
String[] columns = new String[3];
columns[0] = "Sportschool";
columns[1] = "Afstand";
columns[2] = "Score";
this.addTableRow(tableLayout, columns);
//Insert the locations hardcoded (for now).
String[] fitar = new String[3];
fitar[0] = "Fitar";
fitar[1] = "12km";
fitar[2] = "5.0";
String[] rodea = new String[3];
rodea[0] = "Rodea";
rodea[1] = "6km";
rodea[2] = "4.0";
String[] mostreu = new String[3];
mostreu[0] = "Mostreu";
mostreu[1] = "30km";
mostreu[2] = "3.0";
addTableRow(tableLayout, fitar);
addTableRow(tableLayout, rodea);
addTableRow(tableLayout, mostreu);
}
private void addTableRow(TableLayout tableLayout, String[] text) {
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
for (int i = 0; i < text.length; i++) {
TextView column = new TextView(this);
column.setId(tableRows);
column.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
column.setTextColor(Color.BLACK);
column.setText(text[i]);
tableRow.addView(column);
}
//tableRow.setLayoutParams();
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
tableRows++;
}
}
布局.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="150dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="131dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:toolbarId="@+id/toolbar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
<ImageView
android:id="@+id/imageView3"
android:layout_width="68dp"
android:layout_height="83dp"
android:layout_gravity="left|center"
android:layout_marginLeft="30dp"
app:srcCompat="@drawable/logo_rood" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:gravity="bottom|center_horizontal"
android:text="CONFIDENTIAL"
android:textColor="@color/colorAccent" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Sportscholen die voldoen aan uw criteria:"
android:textAlignment="center"
android:textColor="@color/colorAccent"
android:textSize="18sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"></TableLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
提前致谢!
最佳答案
我设法使用这个答案修复它:
https://stackoverflow.com/a/14941587/4653908
在您的 layout.xml 中,将以下内容添加到 TableLayout:
<TableLayout
android:stretchColumns="0,1,2"
</TableLayout>
关于Android 跨页面传播 TableLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42716780/
如果有人能解释这个注释的作用以及我们何时使用它: @Transactional(propagation=Propagation.REQUIRED) 谢谢 最佳答案 如果您需要在 Spring Docs
我有一个页面,它有一个 keydown 事件监听器,用于监听 Escape 键,以便返回。我还有一个简单的模态类,它也监听 Escape 键以关闭它。主页监听器检查模式是否打开,如果打开,则不执行任何
我想在模型中设置默认变量名称 T (=xx) - 将该模型拖到新模型中并在其中定义变量 xx。我收到错误消息:使用未声明的变量 xx。 这是子模型 model test parameter Rea
在 android 2.x 浏览器中查看此示例..它是在我的应用程序中复制场景的示例.. http://johnchacko.net/samples/tap.html 它是关于监听“tap”并从监听器
如您所见,我正在尝试将 GatewayConnectionFailedException 传播到我的 UI。我希望此代码捕获除异常之外的所有内容,我希望表示层捕获该异常以通知用户数据库是问题所在,以便
我目前正在尝试让可执行文件与它需要的所有依赖项正确链接。 这是依赖项的示例结构: exe -> libA -> libB exe和 libA有自己的存储库。 exe拉入libA像这样的东西: add_
有什么方法可以调用带有单个参数的 Scala 函数,给定一个数组 (类似于 JavaScript Spreads在 ECMAScript 6) 中? ys = [10.0, 2.72, -3.14]
我有一个小型静态库,它需要 boost 头文件,并且需要包含目录中的“include”目录。 ... add_library(alib STATIC ...) target_include_direc
我有一些 promise 可以返回对象。 现在我想将它们合并/扩展为一个新对象,因此我使用 Lodash's extend . var whenEverythingIsDone = Promise.a
这是我认为人们通常希望在 Scala 中做的事情,但如果我能在任何地方找到一个例子,我就该死了。 这段代码由于类型删除而无法编译,但它演示了我正在努力完成的事情: def parse[T](json:
这是我认为人们通常希望在 Scala 中做的事情,但如果我能在任何地方找到一个例子,我就该死了。 这段代码由于类型删除而无法编译,但它演示了我正在努力完成的事情: def parse[T](json:
我们有大量 MOSS 2007 站点需要添加大量的 javascript。我编辑、 checkin 、发布并批准了对 default.master 的更改,更改反射(reflect)在根网站上,但没有
请看一下下面的 fiddle :http://jsfiddle.net/K9NjY/ 我在这段代码上花了 3-4 个小时,并将其缩小到最短的版本,但现在我陷入了困境。 问题:1. 点击“divOne”
我读到如果在流程中抛出异常,框架要做的第一件事就是检查消息头中的错误 channel 属性。总是这样吗? 在我的特殊情况下,我将自定义错误 channel 分配给消息 header ,但该消息似乎已向
创建一个小的 C++ 大型精度类,一切似乎都运行良好,但是添加,如果我将 0xffffffff 和 0x04 加在一起,我会得到 0xffff0003,而我应该得到 0x0100000003。这是有问
我正在尝试重新创建 Dan Abramov 类(class)中的 Redux 示例。传播{...store.getState()}在应用程序级别不起作用,Redux 正在更改状态并且 React 不会
考虑一个需要很长时间的事务。在此期间,我想对 TableSmall 执行一些小更新。 ,它应该立即执行,并且主事务的回滚不应该回滚那些小的更新。 我当前的问题是这些小更新将锁定 TableSmall\
我需要对现有函数进行修改,具有一些 const 输入参数: int f(const owntype *r1, const owntype *r2) 为了做到这一点,我想调用一个使用相同类型但没有 co
我有一个带有 ViewModel 的 WPF UserControl: 这个 UserControl 有一个 De
我试图在收到这样的短信时不传播 public class SMSReceiver extends BroadcastReceiver { @Override public void onRec
我是一名优秀的程序员,十分优秀!