내 앱에 데이터가있는 표를 보여주는 활동이 있습니다.TableLayout의 너비
문제는 테이블의 너비를 화면의 전체 너비로 조정할 수 없다는 것입니다. 스마트 폰에서는 테이블 너비가 장치의 너비보다 크기 때문에, 스크롤을 사용합니다. 태블릿에서는 테이블 너비가 그 너비보다 작기 때문에 전체 너비에 맞추고 싶습니다.
XML에서 다음 코드를 사용 : 다음과 같이 내가 적절한 클래스 테이블을 그릴
그것은 ID = GRAFICO와 함께있는 LinearLayout에<?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>
:
@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에 아무 것도 표시 될 수 없다고 생각합니다. ly me.
나는 당신이 저를 도울 수 있기를 바랍니다, 이것은 동일한 메시지를 가진 제 3의 게시물이며 아무도 저에게 답장을하지 않습니다.
감사합니다.
이 양식은 효과가 없습니다. – KryNaC
만약 테이블이 작동하고 전체 너비를 차지하지만 가로 스크롤을 사용하지 않는다면 테이블 또는 세로 스크롤을 테이블과 함께 사용하면 ... – KryNaC