首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >宽度( TableLayout )

宽度( TableLayout )
EN

Stack Overflow用户
提问于 2013-10-18 11:27:01
回答 1查看 146关注 0票数 0

在我的应用程序中,我有一个显示带有数据的表的活动。

问题是我无法将表的宽度调整到屏幕的全部宽度。在智能手机中,表的宽度比设备的宽度要大,所以我使用卷轴,而在平板电脑中,表的宽度小于它的宽度,所以我想要适应总宽度。

xml中使用以下代码

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@color/fondo_pantalla" >

<TextView
    android:id="@+id/Title"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_alignParentTop="true"
    android:text="@string/city_Vld"
    android:textColor="@color/blanco"
    android:gravity="center"
    android:background="@color/color_Vld" />

<TextView
    android:id="@+id/Title_O"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/Title"
    android:textColor="@color/color_Vld"
    android:gravity="center"
    android:background="@color/blanco" />

<LinearLayout
    android:id="@+id/grafico"
    android:layout_width="fill_parent"
    android:layout_heightt="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="5dp"
    android:background="@color/black"
    android:orientation="vertical"
    android:layout_below="@+id/Title_O" />
</RelativeLayout>

它位于LinearLayout with id = grafico中,我在适当的中绘制表,如下所示:

代码语言:javascript
复制
@SuppressWarnings("deprecation")
private void pintaTexto(){

ScrollView scvista = new ScrollView(this);
scvista.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
HorizontalScrollView hscvista = new HorizontalScrollView(this);
hscvista.setLayoutParams(new HorizontalScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
TableLayout tabla = new TableLayout(this);
tabla.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
double numRows = 20;
int numColumns = 4;
// Header of the table
    TableRow cabecera = new TableRow(this);
    cabecera.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    cabecera.setBackgroundColor(getResources().getColor(R.color.azulOscuro_elvg));
    tabla.addView(cabecera);    
// Header data
    for (int j = 0; j < numColumns; j++) {
        TextView textColumna = new TextView(this);
        textColumna.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));                
        textColumna.setText(json.json4.GetInfo(0, j));
        textColumna.setTextColor(getResources().getColor(R.color.blanco));
        textColumna.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        textColumna.setGravity(Gravity.CENTER_HORIZONTAL);
        textColumna.setPadding(5, 5, 5, 5);
        cabecera.addView(textColumna);
    }       
// Data row
        for (int f = 0; f < numRows; f++) {
           TableRow row = new TableRow(this);
           for (int c = 0; c < numColumns; c++) {
                   TextView textDato = new TextView(this);
                   textDato.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, 60));
                   textDato.setText(json.json4.GetValue(f, c));
                   textDato.setTextColor(getResources().getColor(R.color.azulOscuro_elvg));
                   textDato.setBackgroundColor(getResources().getColor(R.color.blanco));
                   textDato.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);                           
                   textDato.setGravity(Gravity.CENTER_VERTICAL);                           
                   textDato.setPadding(15, 0, 15, 0);
                   row.addView(textDato);
           }
           tabla.addView(fila);
        }

hscvista.addView(tabla);
scvista.addView(hscvista);
LinearLayout layout = (LinearLayout) findViewById(R.id.grafico);
layout.addView(scvista); 
}

我已经检查了所有元素的宽度属性,并且我不能像我已经指出的那样适合FILL_PARENT。此外,这个id = grafico的LinearLayout也用于绘制条形图,如果这适合整个屏幕,那么我认为它不能用xml。骗我。

我希望你能帮我,这是我的第三个帖子与相同的信息和任何人答复我任何事情。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-10-18 12:44:00

给出滚动视图的宽度和高度填充父

ScrollView scvista =新ScrollView(this);scvista.setLayoutParams(新LayoutParams(LayoutParams.Fillparent,LayoutParams.Fillparent));HorizontalScrollView hscvista =新HorizontalScrollView(this);hscvista.setLayoutParams(新HorizontalScrollView LayoutParams.Fillparent);TableLayout tabla =新TableLayout(this);tabla.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

试试这个亲爱的:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19448569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档