Android 在TableLayout上拉伸列没有效果
我正在从事一个android项目,我正在利用表格布局,但我遇到了一个问题 正如标题中提到的,我正在使用TableLayout并尝试拉伸所有列以适应屏幕,但由于某些原因,它没有任何影响,所有列都被压到了左侧 下面是XML布局Android 在TableLayout上拉伸列没有效果,android,Android,我正在从事一个android项目,我正在利用表格布局,但我遇到了一个问题 正如标题中提到的,我正在使用TableLayout并尝试拉伸所有列以适应屏幕,但由于某些原因,它没有任何影响,所有列都被压到了左侧 下面是XML布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_heig
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="horizontal">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout android:id="@+id/resultTable"
android:stretchColumns="*"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
下面是我如何填充TableLayout的
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try
{
Log.d("Returned in Result", String.valueOf(result.length()));
resultTable.removeAllViews();
resultTable.setStretchAllColumns(true);
for (int i = 0; i < result.length(); i++)
{
TableRow tr = new TableRow(getActivity());
JSONArray array = result.getJSONArray(i);
Log.d("Returned in Result", "Loaded Columns: " + String.valueOf(array.length()));
for (int j = 0; j < array.length(); j++)
{
//LinearLayout linearLayout = new LinearLayout(getActivity());
//LayoutParams parms = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//linearLayout.setLayoutParams(parms);
TextView textView = new TextView(getActivity());
textView.setText(array.getString(j));
textView.setSingleLine();
//linearLayout.addView(textView);
tr.addView(textView);
}
resultTable.addView(tr);
}
}
catch (Exception ex)
{
Log.e("Load Result", ex.toString());
CrashReporter.ReportCrash(ex, Severity.Critical);
}
}
});
getActivity().runOnUiThread(新的Runnable()){
@凌驾
公开募捐{
尝试
{
Log.d(“在结果中返回”,String.valueOf(Result.length());
resultTable.removeallview();
resultTable.setStretCharl列(true);
for(int i=0;i
谢谢你能提供的帮助
更新
我发现是
水平滚动视图
导致列无法拉伸。如果我重新移动水平滚动视图,它可以正常工作,但使用水平滚动视图时,列不会拉伸。我如何才能让这个工作,因为我需要有水平滚动视图 我可能错了,但我有类似的东西,我没有任何表格布局,但我想在相对布局中有一个滚动视图,所以我必须做一些类似的事情
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/theme"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="34dp" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
这可能没有任何用处,但这就是我的“列被压扁到左边”的原因。问题解决了。
编辑:尝试在滚动视图中使用线性布局