我正在活动中显示来自数据库的数据。我想要一个表格和底部的按钮。对于数据,TableLayout将是最佳选择。我将TableLayout添加到HorizontalView和ScrollView中,以使其垂直和水平滚动。正在动态添加所有行-包括标题。这部分工作正常。
我要的是,当内容小于屏幕宽度时,它仍应占据整个屏幕宽度。例如。如果一张桌子非常适合“纵向”模式,那么对于“横向”模式,它们当然将是右边的空白区域。我不希望该空间eb空,而是要被所有列占用。如果行宽大于屏幕宽度,则根本没有问题-出现水平滚动条。
我尝试了几种变体,但没有任何帮助。不知道要进行什么设置以利用所有空间(如果有的话)并显示它。
是的,还有1期水平滚动条,它出现在最后一行。我希望它显示在最后一行的下面-这样就可以看到最后一行的边框。我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical">
<HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" >
<TableLayout android:id="@+id/browseTable" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginBottom="20dp"
android:background="#FF0000" android:stretchColumns="1,2,3">
</TableLayout>
</HorizontalScrollView>
</ScrollView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center"
android:layout_marginTop="15dp">
<Button android:id="@+id/browseAddBtn" android:text="Add" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" />
<Button android:id="@+id/browseViewBtn" android:text="Edit" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" />
<Button android:id="@+id/browseReturnBtn" android:text="Return" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
输出:

我的 TableLayout 包含 TableRows,每个 TableRows 包含一个子项。
TableLayout 宽度设置为 match_parent 并且工作正常。
TableRow 的宽度自动设置为 match_parent 并且也可以正常工作。
但是,尽管将宽度设置为 match_parent,但 TableRow 的子级不会拉伸到 TableRow 的整个宽度。

我缺少什么?谢谢
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:typefacetv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#772213" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/my_gray"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="0dp" >
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/LODGING_NAME" />
</TableRow>
<TableRow>
<EditText
android:id="@+id/et_hotel_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/borderless_white_5dp"
android:inputType="text"
android:padding="5dp" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:text="@string/STARS" />
<!-- <EditText
android:id="@+id/et_hotel_classtype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/borderless_white_5dp"
android:inputType="number"
android:padding="5dp" /> -->
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我正在使用表格布局内部scrollview它使整个表格可滚动与标题我想使标题不可滚动而表格行将是可滚动的我怎么能实现,表格以编程方式创建这里是我的代码
<ScrollView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FFFFFF" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="450dp"
android:background="#FFFFFF" >
<TableLayout
android:id="@+id/tblTrans"
android:layout_width="450dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 使用INVISIBLE选项隐藏小时为18,19,20,21的行.但它仍然留下了空洞的空白.有没有办法消除这个差距?
private void hideEveningHours() { // hiding evening rows
TableRow tr = (TableRow)findViewById(R.id.row18);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)findViewById(R.id.row19);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)findViewById(R.id.row20);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)findViewById(R.id.row21);
tr.setVisibility(View.INVISIBLE);
}
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-view android-tablelayout
我正在尝试在Android中创建一个表(最低API级别为10),其中一些列必须尽可能地延伸,而有些列需要缩小以适应其内容的大小.
这就是我所拥有的:

(颜色只是看细胞的宽度和高度)
'at'栏就是我所说的.我需要它看起来像这样:
http://img268.imageshack.us/img268/1572/77141b8b8eb443d783cede5.png
这是我现在使用的代码:
ScrollView sv = new ScrollView(this);
TableLayout table = new TableLayout(this);
table.setShrinkAllColumns(true);
table.setStretchAllColumns(true);
table.setPadding(10, 10, 10, 10);
//title row
TableRow rowTitle = new TableRow(this);
rowTitle.setGravity(Gravity.CENTER_HORIZONTAL);
TextView title = new TextView(this);
title.setText("Majors - Season 10");
title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
title.setGravity(Gravity.CENTER);
title.setTypeface(Typeface.SERIF, Typeface.BOLD);
TableRow.LayoutParams params = new TableRow.LayoutParams();
params.span = 4;
rowTitle.addView(title, params);
//header row
TableRow rowHeaders = new TableRow(this);
TextView away = new TextView(this);
away.setText("Away");
away.setTypeface(Typeface.DEFAULT_BOLD);
away.setGravity(Gravity.CENTER_HORIZONTAL);
rowHeaders.addView(away);
TextView empty = new TextView(this);
empty.setText(" ");
// empty.setGravity(Gravity.CENTER_HORIZONTAL);
empty.setBackgroundColor(Color.GREEN); …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个非常简单的 TableLayout,它有 2 列和不确定的行数。在第一列中,我放了一个 TextView,它必须写在 2 行上:
<string name="param_period_data_rec_text">Période d\'acquisition des données\n(secondes)</string>
Run Code Online (Sandbox Code Playgroud)
在第二列中,我放置了一个 EditText。
我的问题是:EditText 的高度大约是 1 行半文本,TableRows 环绕它,隐藏了 TextView 第二行的一半。
当然,我希望 TextView 能够完整显示。我应该怎么做?
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="@color/blanc"
android:orientation="horizontal"
android:padding="20dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/param_frequence_data_rec_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/param_period_data_rec_text"
android:textColor="@android:color/black"
android:textSize="20sp" />
<EditText
android:id="@+id/param_frequence_data_rec_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/param_period_data_rec_input"
android:textColor="@android:color/black"
android:textSize="20sp" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud) 我table在我的代码中动态绘制.在tablerow我的布局,我只是在XML硬编码得到的.我不知道为什么我会收到这个错误,完全没有想法.
TableRow tr = (TableRow) findViewById(R.id.tr);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
TextView textView1 = new TextView(this);
textView1.setGravity(Gravity.CENTER);
textView1.setBackgroundResource(R.drawable.cell_shape);
textView1.setText("1");
textView1.setLayoutParams(rowParams);
tr.addView(textView1);
TextView textView2 = new TextView(this);
textView2.setGravity(Gravity.CENTER);
textView2.setBackgroundResource(R.drawable.cell_shape);
textView2.setText("2");
textView2.setLayoutParams(rowParams);
tr.addView(textView2);
TextView textView3 = new TextView(this);
textView3.setGravity(Gravity.CENTER);
textView3.setBackgroundResource(R.drawable.cell_shape);
textView3.setText("3");
textView3.setLayoutParams(rowParams);
tr.addView(textView3);
TextView textView4 = new TextView(this);
textView4.setGravity(Gravity.CENTER);
textView4.setBackgroundResource(R.drawable.cell_shape);
textView4.setText("4");
textView4.setLayoutParams(rowParams);
tr.addView(textView4);
TextView textView5 = new TextView(this);
textView5.setGravity(Gravity.CENTER);
textView5.setBackgroundResource(R.drawable.cell_shape);
textView5.setText("5");
textView5.setLayoutParams(rowParams);
tr.addView(textView5);
TextView textView6 = new TextView(this);
textView6.setGravity(Gravity.CENTER);
textView6.setBackgroundResource(R.drawable.cell_shape);
textView6.setText("6");
textView6.setLayoutParams(rowParams);
tr.addView(textView6);
TextView textView7 = (TextView) …Run Code Online (Sandbox Code Playgroud) Android Tablelayout是否可以使用xml属性显示所有分隔符(见下图)?
我花了一些时间在网上搜索,发现很多人只是使用自定义视图.
有没有办法在xml或其他更好的方法中执行此操作?
示例(不要介意不同的边框厚度):

我正在以编程方式在表格行中创建多个按钮,但它们总是以左对齐方式结束.我怎样才能将整行排成一行?我正在尝试创建每一行:
TableRow row = new TableRow(getActivity());
TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL);
row.setLayoutParams(params);
for (int j = 0; j != numButtonCols; j++) {
Button b = new Button(getActivity());
b.setOnClickListener(actionListener);
row.addView(b);
actionButtons[j][i] = b;
}
layout.addView(row);
Run Code Online (Sandbox Code Playgroud) 您好我想单击一个按钮,每次单击它时都会向表行添加一个新按钮.在向行添加了3个按钮后,我想动态创建一个新的表行并向其添加一个新按钮.
我知道如果单击一个按钮,如何将一个按钮添加到tableLayout.我不知道每次点击时如何修改表格行,所以我可以添加一个额外的按钮.
任何建议都会非常有帮助和赞赏.
以下是我的代码,但这并不完美
public class DynamicTableView extends Activity {
TableLayout mTlayout;
String[] mTextofButton = { "Dipak", "E", "I", "J", "L",
"M", "G", "R", "N", "T", "H", "P",
"K", "Y", "V" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTlayout = (TableLayout) findViewById(R.id.mTlayout);
TableRow tr=new TableRow(this);
for(int i=0;i<mTextofButton.length;i++){
Button btn=new Button(this);
btn.setText(mTextofButton[i]);
tr.addView(btn);
}
mTlayout.addView(tr);
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我的一个活动中有两个表行.第一行将始终包含2个textview,第二行可能包含一个或两个textview(它取决于userinput).每当我在第二行中有一个textview时,我试图将它跨越到两列.我正在尝试这个
TableRow.LayoutParams param = (LayoutParams)editText.getLayoutParams();
param.span = 2;
txtView.setLayoutParams(param);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.会发生什么,第一行中的第二个txtview被推出屏幕.那么这里的任何人都可以告诉我哪里犯了错误吗?
我收到 StackOverFlowError。我有动态添加按钮的相对布局和表格布局。谁能帮我这个?这是我的代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateButtons();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml. …Run Code Online (Sandbox Code Playgroud) 我需要创建一个ListView或TableLayout每行包含3列和3个按钮,类似于:

但屏幕不仅包含此控件将包含文本字段和其他布局,我需要一个网格采取如下形状(例如).
有关如何实现这一点以及如何处理Button点击的任何想法?由于我是Android的新手,我不知道如何创建它.
