TableLayout cropping

36 views Asked by At

I have a TableLayout inside of a ScrollView like this:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="60dp"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        tools:layout_editor_absoluteX="0dp">

        <TableLayout
            android:id="@+id/notesTable"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:isScrollContainer="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent">

        </TableLayout>
    </ScrollView>

but when I turn the AVD on it appears cropped, like this

TableLayout cropping

I'm adding the elements to my TableLayout programmatically, although the issue appears on the XML design screen too so I don't think it's part of the problem. This is the logic behind it:

notesList.forEach{

    val noteBodyText = sp.getString(it, "Empty Body")!!

    /* Find Tablelayout defined in main.xml */
    val tl = findViewById<View>(R.id.notesTable) as TableLayout
    /* Create a new row to be added. */
    val tr = TableRow(this)
    tr.layoutParams = TableRow.LayoutParams(
        TableRow.LayoutParams.WRAP_CONTENT,
        TableRow.LayoutParams.WRAP_CONTENT
    )
    //note title
    val noteTitle = TextView(this)
    noteTitle.text = it
    noteTitle.setTextColor(getColor(R.color.black))
    noteTitle.textSize = 22F
    noteTitle.layoutParams = TableRow.LayoutParams(
        TableRow.LayoutParams.WRAP_CONTENT,
        30
    )
    tr.addView(noteTitle)

    val noteBody = TextView(this)
    noteTitle.setTextColor(getColor(R.color.dark_gray))
    noteTitle.textSize = 15F
    noteBody.text = noteBodyText
    noteBody.layoutParams = TableRow.LayoutParams(
        TableRow.LayoutParams.WRAP_CONTENT,
        20
    )
    tr.addView(noteBody)

    tl.addView(
        tr,
        TableLayout.LayoutParams(
            TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.WRAP_CONTENT
        )
    )

}

for more context, here is the full XML file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:layout_marginBottom="-90dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/ic_yellow_wide_rectangle"/>

    <Button
        android:id="@+id/backHomeButtonRead"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginEnd="8dp"
        app:icon="@drawable/ic_baseline_home_purple"
        app:iconPadding="4dp"
        app:iconSize="18dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="64dp"
        android:text="Your notes:"
        android:textColor="@color/black"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="@+id/backHomeButtonRead"
        app:layout_constraintStart_toStartOf="parent" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="60dp"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        tools:layout_editor_absoluteX="0dp">

        <TableLayout
            android:id="@+id/notesTable"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:isScrollContainer="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent">

        </TableLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
0

There are 0 answers