我在定位布局元素时遇到问题.我的TableLayout中的AutoComplete和它之后的按钮正在扩展TableRow大于屏幕的宽度.任何人都知道为什么?下面是我的XML代码以及问题的图片.
提前致谢!!
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView android:id="@+id/installation"
android:textSize="14sp" android:completionThreshold="3" />
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_find" android:text="@string/btn_find"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/error" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingTop="20px"
android:textColor="#FF0000" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我在网上查看了使用DIV实现表单的示例,我看到的只是一个非常简单的列表单.我有一些相当复杂的表格,这是一张图片:
http://img835.imageshack.us/img835/8292/formn.jpg
很容易让它与表(我这样做)一起工作,我唯一的问题是有时我需要不显示一些选项并将值向上移动一行以避免间隙.
我开始使用div创建一些表单,但是当我更改浏览器窗口大小并且不容易对齐时它们会分崩离析.
这个主题很有用: 在html中显示表单时使用表标签是不是很糟糕? 但它没有解决我的一些担忧.
你会建议什么作为解决方案?我可以动态删除/插入表中的值或尝试执行DIV.
我该怎样做才能得到类似的东西:

我可以在HTML中没有问题但在Android中如何做到这一点?
如果您知道如何添加两个滚动条,请帮助我.
首先,我清楚所有人.
我在tablelayout中添加了两个滚动条,但主要问题是使用动态数据来填充tablerow.因此,如果只有一个记录,那么水平滚动视图顶部在数据之后.但我想在底部显示水平,也显示垂直.
谢谢
Prashant
这是一个例外:
java.lang.NullPointerException
at android.widget.TextView.setTextColor(TextView.java:1787)
at android.widget.TabHost$LabelIndicatorStrategy.createIndicatorView(TabHost.java:521)
at android.widget.TabHost.addTab(TabHost.java:204)
at com.android.layoutlib.bridge.Bridge.setupTabHost(Bridge.java:880)
at com.android.layoutlib.bridge.Bridge.postInflateProcess(Bridge.java:807)
at com.android.layoutlib.bridge.Bridge.postInflateProcess(Bridge.java:813)
at com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:401)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.computeLayout(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange(Unknown Source)
at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:290)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1282)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1267)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1061)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2743)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1429)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at …Run Code Online (Sandbox Code Playgroud) 我有一个表填充不同长度的文本.我已经将table-layout css属性设置为fixed,因为它不断地将表推到它的父对象之外创建一个水平滚动条.
我希望我的td正好是桌子的一半,这将是它的父级的全尺寸.我希望我的文本包含在td中.这是它的样子:

我希望文本环绕20,因此它不会与其他文本重叠.我不能用<br />.
这里是一个的jsfiddle的问题.
编辑:Nick Beranek回答了这个问题,但我正在寻找发生这种情况的原因.当<br />标签不在这样的表中时,默认情况下会自动换行而不添加CSS.有人可以向我解释为什么它在这种情况下不起作用?
似乎我不是第一个动态创建TableLayOut的人.问题是,当我将TableRow对象添加到TableLayout时,我的android应用程序崩溃并完成了意外错误.
我想做的事?我想用下一个项目布局创建对话框
-------------------
|Custom |____|____| <-- Something like property grid
|graphic|____|____|
|view |____|____|
| |____|____|
-------------------
Run Code Online (Sandbox Code Playgroud)
为了做到这一点,我正在使用下一个方法.
1.创建DialogLayout类
2.创建Dialog类
public class DialogLayout extends LinearLayout
{
private CustomView m_view;
private TableLayout m_layout;
private TableRow m_row0;
private TextView m_propName;
private EditText m_propValue;
public DialogLayout(Context context)
{
super(context);
Init(context);
}
private void Init(Context context)
{
setOrientation(LinearLayout.HORIZONTAL);
m_layout = new TableLayout(context);
m_layout.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
m_layout.setStretchAllColumns(true);
m_propName= new TextView(context);
m_propName.setText("PropName:");
m_propValue = new EditText(context);
m_propValue.setText("--");
m_row0 = new TableRow(context);
m_row0.addView(m_propName);
m_row0.addView(m_propValue);
m_layout.addView(m_row0, …Run Code Online (Sandbox Code Playgroud) 我有一个函数从网页获取产品列表,我想在tableLayout中为列表的每个元素添加一行.
public void getProductsOfCategory() throws IOException{
new Thread(){
public void run(){
//background code...
try {
Bundle extras = getIntent().getExtras();
String categoryName = extras.getString("categoryName");
HttpGet httpget = new HttpGet("http://romal.hopto.org/foodadvisor/users/getProductsOfCategory.json?category="+categoryName);
HttpResponse httpresp = httpClient.execute(httpget);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
httpresp.getEntity().writeTo(baos);
final String content = new String(baos.toByteArray());
CategoryActivity.this.runOnUiThread(new Runnable(){
public void run(){
//foreground code (UI)
//update user interface, for example, showing messages
try {
JSONObject jObject = new JSONObject(content);
JSONArray productsList = jObject.getJSONArray("response");
for(int i=0; i<productsList.length();i++){
JSONObject product = productsList.getJSONObject(i);
JSONObject productData = …Run Code Online (Sandbox Code Playgroud) 我正在为android设计一个基本的sudoko游戏.我想要一个4x4的表格,其中所有单元格都是正方形.
我正在尝试使用16个按钮TableLayout.
我的方式看起来像这样

他们是rectange形状:(
我的xml
<TableLayout
android:id="@+id/tl"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center" >
<Button
android:id="@+id/button1"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="1" />
<Button
android:id="@+id/button2"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="2" />
<Button
android:id="@+id/button3"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="3" />
<Button
android:id="@+id/button4"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="4" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/button5"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="5" />
<Button
android:id="@+id/button6"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="6" />
<Button
android:id="@+id/button7"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="7" />
<Button
android:id="@+id/button8"
style="@style/box_sky_blue"
android:layout_weight="1"
android:text="8" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" …Run Code Online (Sandbox Code Playgroud) 我正在开发我编写的 Android 应用程序的 iOS 版本,但我无法找出显示表格数据的最佳方式。Android 有 TableLayout 和 TableRow,使任务相当简单。
额外需要注意的是,无论我如何创建数据表,它都需要以编程方式创建,因为要显示的表数量不确定,并且每个表都有不确定的行数(所有信息都是从 Web 服务中提取的)。
另外,如果有帮助的话,该应用程序的方向仅限纵向。
这是一个(丑陋的)表格外观示例。
任何帮助都是极好的。谢谢!