Я старался изо всех сил, чтобы решить проблему, но я не могу найти решение. Я пытаюсь установить текст в строки в макете таблицы в android. Иногда он появляется с неправильным направлением, а иногда не отображается вообще. Я ценю вашу помощь и ваши ответы. Вот коды Java Код. В коде я загрузил две стороны кодов. Часть java и xml.
package com.example.databaseapp;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
TableLayout tblayoutl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
tblayoutl=findViewById(R.id.tblayout);
String code="123",subject="physics",grades="45",finals="pass";
TableRow tableRow = new TableRow(this);
tblayoutl.addView(tableRow);
TextView textView1 = new TextView(this);
textView1.setText(code);
textView1.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
tableRow.addView(textView1);
TextView textView2 = new TextView(this);
textView2.setText(subject);
textView2.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
tableRow.addView(textView2);
TextView textView3 = new TextView(this);
textView3.setText(grades);
textView3.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
tableRow.addView(textView3);
TextView textView4 = new TextView(this);
textView4.setText(finals);
textView4.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
tableRow.addView(textView4);
/*
TableRow tableRow = new TableRow(this);
tblayoutl.addView(tableRow);
TextView textView2 = new TextView(this);
TextView textView3 = new TextView(this);
TextView textView4 = new TextView(this);
textView1.setGravity(Gravity.LEFT);
textView1.setTextColor(Color.BLUE);
textView1.setText(code);
tableRow.addView(textView1);
textView2.setGravity(Gravity.LEFT);
textView2.setTextColor(Color.BLUE);
textView2.setText(subject);
tableRow.addView(textView2);
textView3.setWidth(1);
textView3.setGravity(Gravity.LEFT);
textView3.setTextColor(Color.BLUE);
textView3.setText(grades);
tableRow.addView(textView3);
textView4.setWidth(1);
textView4.setGravity(Gravity.LEFT);
textView4.setTextColor(Color.BLUE);
textView4.setText(finals);
tableRow.addView(textView4);
*/
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity"
android:splitMotionEvents="true"
android:orientation="vertical"
android:background="#FBFBFB"
>
<TableLayout
android:id="@+id/tblayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#F1E5F3">
<TableRow>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="190dp"
app:srcCompat="@mipmap/a" />
</TableRow>
<TableRow android:layout_marginTop="20dp">
<TextView
android:id="@+id/welcomeMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="This is Online Grade App"
android:textStyle="bold" />
</TableRow>
<TableRow android:layout_marginTop="25dp">
<TextView
android:id="@+id/StudentName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textStyle="bold" />
</TableRow>
<TableRow android:layout_marginTop="15dp">
<TextView
android:id="@+id/StudentStage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textStyle="bold" />
</TableRow>
<TableRow android:layout_marginTop="30dp">
<TextView
android:id="@+id/Code"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Code"
android:textStyle="bold" />
<TextView
android:id="@+id/Subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Subject"
android:textStyle="bold" />
<TextView
android:id="@+id/Grades"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Grades"
android:textStyle="bold" />
<TextView
android:id="@+id/finals"
android:layout_width="match_parent"
android:layout_height="match_parent"
> android:layout_weight="1"
android:gravity="center"
android:text="Finals"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
![enter image description here](https://i.stack.imgur.com/CZ6xC.png)