有2x2网格(动态使用TableLayout)需要在其上显示图像.现在基于图像大小,意味着 - 如果图像适合1个细胞意味着1个细胞,那么大意味着2个细胞或4个细胞基于大小(我知道它将占用多少个细胞)
我可以在1个单元格中显示图像,但问题是如果图像需要2个单元格(第1列)如何在2个单元格中显示图像(没有干扰网格)
我在设置表行(包含文本视图)的布局参数时遇到一些困难.
我想添加一些列以获得良好的布局.我是动态地做的.(在代码中)
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bye"/>
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我希望这两个textviews相应地成为两列和屏幕上的布局.
我试图了解如何动态地将列和行添加到tablelayout.
我有这个简单的例子.但是,它只显示运行时的第一列.
有人能告诉我缺少什么才能显示四列而不是一列吗?
package com.apollo.testtablelayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class TestTableLayoutActivity extends Activity {
/** Called when the activity is first created. */
String col1;
String col2;
String col3;
String col4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout tl = (TableLayout) findViewById(R.id.tableLayout1);
for (int x = 1; x < 10; x++) {
col1 = "(" + x + ") Column 1";
col2 = "(" + x + ") Column 2";
col3 …Run Code Online (Sandbox Code Playgroud) 我正在使用表格布局来显示数据,如下所示.

我想做的事 ?
我希望第二列中的文本对齐到左侧,文本应该换行并显示在下一行中,并且如图所示.
码:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp" >
<ImageView
android:id="@+id/place_category_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:contentDescription="ss"
android:paddingRight="10dp"
android:src="@drawable/icon_category"
android:textAlignment="textStart" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:text="230 kms"
android:textSize="16sp" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp" >
<ImageView
android:id="@+id/place_category_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:contentDescription="ss"
android:paddingRight="10dp"
android:src="@drawable/icon_category"
android:textAlignment="textStart" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:text="Hill Station, Wild Life"
android:textSize="16sp" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp" >
<ImageView
android:id="@+id/place_category_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true" …Run Code Online (Sandbox Code Playgroud) 我有一个tableLayout有两列和两行,两行和最后一列都有match_parent的宽度,但布局没有填充父宽度,它像自己的wrap_content一样自我组合.
这是代码:
<TableLayout android:layout_width="match_parent">
<TableRow android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="static" />
<EditText
android:layout_width="match_parent"
android:text="text" />
</TableRow>
<TableRow android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="static2" />
<EditText
android:layout_width="match_parent"
android:text="text2" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
对于具有父级宽度的每一行,我需要做什么?
Ps:我工作的地方不允许我发布我的代码,所以我编写了尽可能接近我的代码的代码.我不知道它是不对的,我无法测试.
我正在尝试对齐表格行中的项目(左/中/右位置),但我可以点到它的工作可以有人帮我看下面的片段,,,
表行
应该对齐textview1 = left textview2 = center imgview1 = right
表行的xml
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/focast_day"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="false"
android:singleLine="true"
android:text="@string/na_msg"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/focast_day_temp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="false"
android:singleLine="true"
android:text="@string/na_msg"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/focast_day_skyIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="right"
android:scrollHorizontally="false" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
myTableLayout
<TableLayout
android:id="@+id/weatherforcastTable"
android:layout_width="fill_parent"
android:stretchColumns="2"
android:layout_height="wrap_content"
android:layout_below="@+id/today_temp"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp" >
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
用于将数据填充到表行的代码
for (Forecastday forecastday : forcastDayList) {
View view = inflater.inflate(R.layout.weather_forcast_day_view, null);
TextView focast_day …Run Code Online (Sandbox Code Playgroud) 我想创建一个带有列分隔符的表.我想用垂直条形图像划分我的列.为了达到这个目的,我已经习惯了"android:divider="@drawable/abc" 但是没有用.下面是我的xml文件:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:stretchColumns="*"
android:padding="5dip"
android:divider="@drawable/tracking_green"
>
<TableRow >
<TextView
android:id="@+id/retaileritem1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="xxxxxxx" />
<TextView
android:id="@+id/retaileritem2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="xxxxxxx" />
<ImageView
android:id="@+id/retailerimage1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/tracking_green" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我正在尝试为我的应用程序中的某些项目创建一个表格/网格,我希望在每个单元格周围有一个边框来分割项目,并将设置与项目保持一致.这个应用程序将用于工业环境中,可能有不熟悉Android的人需要使用它,因此试图让它尽可能简单.
表/格将包含TextView,EditText,Spinner,和Button,并且也将滚动(经由ScrollView亲本).
我读到GridView并发现它(似乎)只能以编程方式获取项目,如果我错了请纠正我.我觉得这是不必要的,因为我知道我想要什么,在哪里.此外,我还没有尝试以编程方式添加项目到布局,所以我想我会先尝试其他选项.此外,如果自动显示边框线,或者您可以完全显示边框线,则GridView文档不会说明这种方式.
我开始使用a TableLayout并且能够获得除边界线之外的所有内容.我试图android:divider获得线条,但这不起作用.我曾经想过要创建一堆TextView带有黑色背景和~2dp宽度/高度的s来制作我自己的边框线.这感觉就像是一个巨大的浪费.然后我还阅读了TableLayout文档并发现:"TableLayout容器不显示其行,列或单元格的边框线."
然后我尝试了,GridLayout并得到了相同的结果TableLayout.我试过padding和margins,既不工作.此外,GridLayout文档指出:"网格由一组无限细线组成,将观察区域分隔成单元格."
我的问题是:
是否存在我错过的TableLayout或者GridLayout通过xml给我边界线的声明?
如果没有,那么GridView我会给我想要的台词吗?
我可以添加我想要的所有以前提到的项目GridView吗?
android android-gridview android-tablelayout android-gridlayout
我正试图在我的TableLayout中实现40/60%的分割,但我没有运气.在我的Android设备上测试代码时,左侧TextView仍然占用了60%,而不是40%.
任何帮助都会很棒:
<TableLayout
android:id="@+id/agentStatusTable"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center|top"
android:visibility="visible"
android:background="@drawable/curvedbg"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
>
<TableRow android:id="@+id/webiprow" android:layout_marginTop="14sp" android:gravity="center_vertical" android:background="#e5e6e6" android:minHeight="45sp" android:weightSum="1">
<TextView android:paddingRight="10dp" android:id="@+id/webiptitle" android:text="@string/webip" android:textColor="#000000" android:textSize="15sp" android:layout_weight="0.40" android:gravity="right"></TextView>
<TextView android:paddingRight="10dp" android:id="@+id/webiptext" android:textColor="#000000" android:textSize="15sp" android:layout_weight="0.60" android:gravity="right"></TextView>
</TableRow>
<TableRow android:id="@+id/webportrow" android:layout_marginTop="6dp" android:layout_marginBottom="14sp" android:gravity="center_vertical" android:minHeight="45sp" android:weightSum="1">
<TextView android:paddingRight="10dp" android:id="@+id/webporttitle" android:layout_weight="0.40" android:text="@string/webport" android:textColor="#000000" android:textSize="15sp" android:gravity="right"></TextView>
<EditText android:paddingRight="10dp" android:inputType="number" android:layout_weight="0.60" android:id="@+id/EditText01" android:text="@+id/EditText01"></EditText></TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud) android tablerow android-layout android-tablelayout android-layout-weight
我想为Android应用程序创建一个登录屏幕.我正在使用TableLayout正确的对齐方式.因此,两行由a TextView和a组成,EditText我想Button在它们下方添加一个宽度拉伸到屏幕.所以我把它Button放在另一个TableRow,我添加layout_span="2"了Button,但是Button显示在第一列.
我认为这应该是正确的,但我必须在xml文件中做错.你知道出了什么问题吗?
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".LoginActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="15dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/evUsername" />
<EditText
android:id="@+id/username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="15dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/evPassword" />
<EditText
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPassword" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="@string/btnLogin" />
</TableRow>
</TableLayout> …Run Code Online (Sandbox Code Playgroud)