我有一个LinearLayout垂直方向,在第一行我添加了一个填充父母的按钮.
我想使用TableLayout实现相同的功能.
到目前为止我尝试过的是:

<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/firstRow">
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow >
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
该TableRow填充母,但是行内的按钮将不会填充整个行.
如何使按钮像这样填充父母?

以及如何使它垂直填充父母像这样:

我有一个表格布局,每行包含两个编辑文本和一个微调器,我想将它放在相对布局的中心,但是我无法解决它。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/Relative_4"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/SomePhoto" />
<TableLayout
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:clickable="false"
android:duplicateParentState="false"
android:focusable="false"
android:layoutDirection="rtl"
android:focusableInTouchMode="false"
android:longClickable="false"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="true" >
<EditText
android:id="@+id/editText_4_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:duplicateParentState="false"
android:ems="5"
android:focusable="false"
android:focusableInTouchMode="false"
android:freezesText="false"
android:gravity="center_vertical|center_horizontal"
android:inputType="none"
android:longClickable="false"
android:scrollHorizontally="false"
android:text="Course"
android:textAllCaps="false" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText_4_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:duplicateParentState="false"
android:ems="6"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical|center_horizontal"
android:inputType="none"
android:longClickable="false"
android:text="credit hours"
android:layout_centerHorizontal="true" />
<EditText
android:id="@+id/editText_4_3"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 在android中创建表格布局或recyclerview/listview/gridview 的最佳方法是什么,它可以在每行大约1000行和大约50列中提取大量数据而不会崩溃?
我想像excel表一样展示它没什么特别的,只是显示数据当然滚动两种方式.
我正在开发一个生成Android的应用程序pdf.
我itextpdf用来生成pdf.
我有以下问题:
我有一个有3行的表,当这个表靠近页面的末尾时,有时会在一页上放一行,在下一页放两行.
有没有办法强制这个表在下一页开始,所以我可以在下一页上有完整的表格?
谢谢
我在 .xml 文件中定义了一个表,但必须动态添加行和标题。我在水平和垂直方向的表格行填充宽度有问题。我试过stretchColumns参数,但没有帮助。最好的方法是什么?
table = (TableLayout) findViewById(R.id.testList);
TableRow headerRow = new TableRow(this);
JSONObject obj;
obj = new JSONObject(loadJSONFromAsset());
JSONArray records = obj.getJSONArray("tests");
ArrayList<String> headers = new ArrayList<>();
headers.add("Header 1");
headers.add("Header 2");
headers.add("Header 3");
headers.add("Header 4");
headers.add("Header 5");
for(int i = 0; i < headers.size(); i++) {
TextView header = new TextView(this);
header.setText(headers.get(i));
header.setTextColor(Color.WHITE);
header.setBackgroundColor(Color.rgb(24, 116, 205));
header.setPadding(15, 15, 15, 15);
header.setTextSize(20);
header.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
header.setMaxLines(1);
headerRow.addView(header);
}
table.addView(headerRow);
Run Code Online (Sandbox Code Playgroud)
和 xml
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView …Run Code Online (Sandbox Code Playgroud) 我想创建一个表来显示这样的东西:
________
|__|__|__|
|__|__|__|
Run Code Online (Sandbox Code Playgroud)
所有盒子都需要均匀分割,底行中间的盒子将有一个非常大的图像,将被强制缩小.这是我目前的XML布局,但我最终得到了这样的布局:
________
|_|____|_|
|_|____|_|
Run Code Online (Sandbox Code Playgroud)
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="Unused"
android:padding="3dip" />
<TextView
android:layout_column="2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="Top Center"
android:padding="3dip" />
<TextView
android:layout_column="3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="Unused"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="---->" />
<ImageView
android:id="@+id/mainImg"
android:layout_column="2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<TextView
android:layout_column="3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="<----" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Marquee在textview中不起作用.我将textview放在两个按钮之间的TableLoyout中.我将textview作为可伸缩的列.这是我的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:background="#e0bf64" android:orientation="vertical">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="2"
android:background="#f2cd6d">
<TableRow>
<Button
android:id="@+id/btn_prv"
android:text="@string/prv"
android:textSize="16sp"
android:layout_column="1"
android:layout_width="100dip"
android:background="@drawable/prev_btn_re"
android:paddingLeft="0sp"
android:paddingTop="0sp"
/>
<TextView
android:id="@+id/head_title"
android:layout_width="125dip"
android:gravity="center"
android:paddingLeft="5sp"
android:paddingTop="10dip"
android:paddingRight="0sp"
android:background="#f2cd6d"
android:textSize="16sp"
android:textColor="@color/black"
android:marqueeRepeatLimit="marquee_forever"
android:lines="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:scrollHorizontally="true"
android:text="marquee text"
/>
<Button
android:id="@+id/btn_next"
android:text="@string/next"
android:textSize="16sp"
android:gravity="right"
android:layout_width="100dip"
android:background="@drawable/next_btn_re"
android:paddingRight="10sp"
android:paddingTop="5sp"
/>
</TableRow>
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请任何人告诉我为什么它不起作用?
我无法将TableLayout中的行放在屏幕中央.我正在尝试创建一个4x4的可点击图像表,并希望它们在屏幕上居中.最后绘制它们左对齐,我希望它们以两侧的空间为中心.这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp">
<TableRow android:layout_gravity="center_horizontal">
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp"
android:layout_gravity="center" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp"
android:layout_gravity="center" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp"
android:layout_gravity="center" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp"
android:layout_gravity="center" />
</TableRow>
<TableRow android:layout_gravity="center_horizontal">
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp" />
</TableRow>
<TableRow android:layout_gravity="center_horizontal">
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="3dp" />
<ImageView android:src="@drawable/rocket"
android:layout_width="60dp" …Run Code Online (Sandbox Code Playgroud) 我正在TableLayout为其动态添加行.在每行中有2个元素,其中一个是TextView另一个元素Button.当我单击一行中存在的按钮时,应该删除该行.如何在Android中完成?如何查找rowid以及如何动态删除行.任何人都可以帮我解决这个问题.
例如,我以编程方式创建了4个表格,我希望每个表格高度为屏幕的1/4大小.每个桌子高度是屏幕尺寸的一半.我尝试了不同的方法,但是桌子高度并没有改变.我管理更改tablerow宽度,但高度没有.这是我的代码:
@SuppressLint("NewApi")
public class GameActivity extends Activity {
private Context context;
public void drawTable(){
int i;
TableLayout table = new TableLayout(context);
table.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
//table.setStretchAllColumns(true);
//table.setShrinkAllColumns(true);
//table.setWeightSum(1.0F);
TableRow[] rows = new TableRow[5];
for(i = 0; i < 4; ++i){
rows[i] = new TableRow(context);
rows[i].setBackgroundResource(R.drawable.images214);
rows[i].setWeightSum((float)1.0);
rows[i].setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 10));
//rows[i].setScaleY(0.25F);
table.addView(rows[i]);
}
LinearLayout l = (LinearLayout) findViewById(R.id.linear);
l.addView(table);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
context = this;
// TableLayout table = new TableLayout(this);
// TableRow row1 = new …Run Code Online (Sandbox Code Playgroud) android tablerow layoutparams android-4.0-ice-cream-sandwich android-tablelayout
android ×10
java ×3
tablerow ×2
xml ×2
android-4.0-ice-cream-sandwich ×1
itextpdf ×1
layout ×1
layoutparams ×1
marquee ×1
tablelayout ×1
textview ×1